Hi, so I want to say,
while p is less than the length of the list
for everything in my list (punctuation and characters)
if the letter or punctuation is in my valid letter string
convert it into ascii using ord()
that equals one turn p = p + 1
else if it not in my valid letter string
append it into a list
and then print it, after the while loop

Then I want to say
for every number in the list
excluding those not in my valid letter string
add to another variable i have (its an integer)
however if the result is greater then 126
then take 94 away from it
and change it into character into the ascii character using chr()
Then i want to put all of this into a string
Any help would be greatly appreciated
Here's what i have to start

        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())
        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))
#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
#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
#=============================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]
#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)
        banane = 0 
        for ch in ascii_conversion:
            if ch in validLetters:
                tangerine = len(ascii_conversion)
                banane= banane + 1
        guava = []
        p = 0
        conversion = []
        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 == ' ':

What is the actual problem? Is there a traceback when you run it? You say:

while p is less than the length of the list...

..which is basically describing what your code does. Can you give me a more general explanation? Like "I want to shift the ordinance of every character in a string."? I see some patterns here that can be shortened:


n = 0
number = []
while n<8:
    random_number = chr(random.randint(33, 126))
    n = n + 1
    characters = ord(random_number)

Could be written much cleaner as (untested):

# A list of 8 random character ordinances (numbers)
numbers = [random.randint(33, 126) for _ in range(8)]

Which is also easy to work with when building strings or whatever:

# That same list converted to characters
actualchars = [chr(n) for n in numbers]

# That character list as a string.
actualstring = ''.join(actualchars)

# All in one go (using a generator)
randomstring = ''.join((chr(random.randint(33, 126)) for _ in range(8)))

It's a much shorter version of this for-loop:

numbers = []
for _ in range(8):
    numbers.append(random.randint(33, 126))

This way you don't have to do so much bookkeeping. Also, there is no reason to go from int -> chr -> ord (line #15 and #21), because ord(chr(47)) == 47. Python is good at list comprehensions and generators, so there is no reason to build a simple list like this with a while loop (for more complicated processing, maybe, but for-loops are possibly even better).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.