Hey, Guys and Gals.
For some reason the variable text_list seems to be modified after the variable final has been modified.
text_list is a list of text :)
Full code is below. Any other hints and tips would be great
Thanks a bunch.
decode_list = []
key = 0
final = text_list
loop = 0
while key <= len(chars):
for x in text_list:
if x in chars:
final[loop] = chars[int((chars.index(x) - key) % len( chars ))]
loop += 1
decode_list.append(''.join( final ))
key += 1
loop = 0
---------------------------------------------------------------------
# Caesar Cipher Decrypt/Encrypt Program
# Used to decrypt/encrypt Caesar Ciphers.
# -- IMPORTS --
import string
# -- VARIABLES --
# -- OPERATIONS --
ENCODE = 76765
DECODE = 89671
# -- CHARACTER ENCODINGS --
BASIC_ALPHABET = list(string.ascii_letters)
VOWELS = [ 'a', 'e', 'i', 'o', 'u', 'A', 'I', 'E', 'O', 'U' ]
# Code Start:
text_in = raw_input('Please enter the text you wish to be decoded/encoded: \n') # Enter the text you wish to change.
def RepresentsInt(s): # Write own for v0.3
try:
int(s)
return True
except ValueError:
return False
def ask_operation():
operation_q = raw_input('What operation would you like to perform: [e]ncode or [d]ecode: ').lower() # Ask what they would like to do.
if operation_q in ('d', 'decode'):
return DECODE
elif operation_q in ('e', 'encode'):
return ENCODE
def encode( text ):
chars = ''
shift = -1
text_list = list( text )
while chars == '':
char_set = raw_input('default - 26 letter alphabet(upper and lower) |\nWhat character encodeing would you like to use: ' )
if char_set == '':
chars = BASIC_ALPHABET
while shift not in range(1, len(chars)):
shift = int(raw_input('What character shift would you like ( 1 - ' + str( len( chars ) + 1 ) + ' ): '))
final = text_list
loop = 0
for x in text_list:
if x in chars:
final[loop] = chars[int((chars.index(x) + shift) % len( chars ))]
loop +=1
encoded = ''.join( final )
print encoded
def decode( text ):
chars = ''
key = 1097962
text_list = list( text )
while chars == '':
char_set = raw_input('default - 26 letter alphabet(upper and lower) |\nWhat character encodeing would you like to use: ' )
if char_set == '':
chars = BASIC_ALPHABET
while True:
key = raw_input('What is the Decryption key ( 1 - ' + str( len( chars ) + 1 ) + ' or leave blank if unknown ): ')
if RepresentsInt( key ):
key = int( key )
final = text_list
loop = 0
for x in text_list:
if x in chars:
final[loop] = chars[int((chars.index(x) - key) % len( chars ))]
loop += 1
decoded = ''.join( final )
print decoded
break
elif key == "":
# Brute Force
decode_list = []
key = 0
final = text_list
loop = 0
while key <= len(chars):
for x in text_list:
if x in chars:
final[loop] = chars[int((chars.index(x) - key) % len( chars ))]
loop += 1
decode_list.append(''.join( final ))
key += 1
loop = 0
vowel_list = []
print decode_list
for phrases in decode_list:
phrase_vowel = 0
word_vowel = 0
word_list = phrases.split()
for words in word_list[:]:
vowel = 0
letter_list = list(words)
for letter in letter_list[:]:
if letter in VOWELS:
vowel += 1
if vowel > 0:
word_vowel += 1
if word_vowel > int(round(len(word_list)*0.9)):
vowel_list.append( phrases )
if vowel_list:
vowel_list.sort()
last = vowel_list[-1]
for i in range(len(vowel_list)-2, -1, -1):
if last == vowel_list[i]:
del vowel_list[i]
else:
last = vowel_list[i]
print vowel_list
break
operation = ''
while operation == '':
operation = ask_operation()
if operation == ENCODE:
encode( text_in )
elif operation == DECODE:
decode( text_in )