hi, soat the moment i am writing an encryption program, i am not quite sure how to use for loops for lists,
my list at the moment is this:
Somewhere in la Mancha, in a
place whose name I do not care
to remember, a gentleman lived
not long ago, one of those who
has a lance and ancient shield
on a shelf and keeps a skinny
nag and a greyhound for racing.
basically i want to convert the character to ASCII (b = 66) but not if it is a space (32), and then separate each integer and add every integer excluding spaces to another variable I have
After p< tangerine is where
i am having trouble, it just ignores my code and stops after this point
Thanks very much, any help/advice will do!
text_file = input(str("Enter the file you want to be Encyrpted"))
ciphertext_file = input("Enter the file to write the encrypted message out to: ")
#this will find the text file the user has inputter
apple = open(text_file,"r")
#this puts the text file so it can only be read
apple =(apple.read())
print(apple)
n = 0
number = []
texting = []
#================================8 Character Key =================================================
#while n is less than 8
while n<8:
#it will convert a random number between 33 and 126 into ascii
random_number = chr(random.randint(33, 126))
print(random_number)
#every time n + 1
#one turn out of 8
n = n + 1
#the number is put into ascii
characters = ord(random_number)
#it is put into the number list
number.append(characters)
print(number)
#this rounds each of the eight integers in number and divides by 8 and takes away 3
#==================Offset factor====================
offset_number = round((number[0]+number[1]+number[2]+number[3]+number[4]+number[5]+number[7])/8)-32
#this prints the offset factor
print(offset_number)
#=============================Task 5=====================================================================
newString = []
#this is the only part of ascii allowed
validLetters = "#$%&'()*+,-./:;<=>?@[\]^_`{|}~""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghiklmnopqrstuvwxyz{|}~"
space = [' ']
new = []
old = []
x = 0
#this splits the text file into singukar characters from 0 to 1
chrsplit = [apple[i:i+1] for i in range(0, len(apple),1)]
#this puts into ascii every character
ascii_conversion = [ord(i) for i in chrsplit]
print(ascii_conversion)
#this replaces each 32 in the list with a space
ascii_conversion= "".join(chr(n) for n in ascii_conversion)
ascii_conversion = textwrap.fill(ascii_conversion, 32)
print(ascii_conversion)
banane = 0
for ch in ascii_conversion:
if ch in validLetters:
tangerine = len(ascii_conversion)
else:
banane= banane + 1
guava = []
p = 0
conversion = []
print(tangerine)
while p<tangerine:
for z in ascii_conversion:
if validLetters in ascii_conversion:
chars = [ascii_conversion[i:i+1] for i in range(0, len(ascii_conversion ),1)]
mylist = [ord(i) for i in chars]
p = p + 1
elif x == ' ':
guava.append(x)
print(mylist)