I have made a cipher substitution program which would take some input and print a coded output.
however,the required output is not coming.
My program first asks for input.then it converts it into a list as it is mutable.ALso,a string of all the alphabets is declared too.
#cipher code substitution program
I = raw_input("Enter message:")
Alpha = "abcdefghijklmnopqrstuvwxyz"
I = list(I)
count=0
for x in Alpha:
y = 25- count
while x in I > 0:
I[I.index(x)] = Alpha[y]
count += 1
continue
print(I)
for loop is used which will iterate over the alpha string one by one.I have used a counter to number the alphabets 0-a 1-b and so on.The cipher formula is the {y=25 - count}.So a corresponds to z. etc
The while loop checks if x(alphabet) is in l (list of input) and executes the loop.I used I.index(x) so it gives the index of the first occurrence of x and the corresponding cipher is assigned through Alpha[y].
This will continue till all the alphabets are done .
Now I want the program to take my input and encode it like this:
I type 'abc' the output would be 'zyx'
However it gives :
Enter message:abc
['a', 'b', 'c']
What is the problem with my program?If you can suggest a simpler and efficient way to do cipher substitution please do so.I am kind of a beginner too.