I am making a word encryption for my school and couldn't figure out how to turn it from single digit encryption into a full word. I want to be able to do full words not one letter at a time. I would be extremely grateful if anyone could help me out with this problem
while True:
print("Input letters you would like to encrypt")
IN= input()
if IN=="a":
print("BCDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="A":
print("BCDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="b":
print("ACDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="B":
print("ACDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="c":
print("ABDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="C":
print("ABDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="d":
print("ABCEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="D":
print("ABCEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="e":
print("ABCDFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="E":
print("ABCDFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="f":
print("ABCDEGHIJKLMNOPQRSTUVWXYZ")
elif IN=="F":
print("ABCDEGHIJKLMNOPQRSTUVWXYZ")
elif IN=="g":
print("ABCDEFHIJKLMNOPQRSTUVWXYZ")
elif IN=="G":
print("ABCDEFHIJKLMNOPQRSTUVWXYZ")
elif IN=="h":
print("ABCDEFGIJKLMNOPQRSTUVWXYZ")
elif IN=="H":
print("ABCDEFGIJKLMNOPQRSTUVWXYZ")
elif IN=="i":
print("ABCDEFGHJKLMNOPQRSTUVWXYZ")
elif IN=="I":
print("ABCDEFGHJKLMNOPQRSTUVWXYZ")
elif IN=="j":
print("ABCDEFGHIKLMNOPQRSTUVWXYZ")
elif IN=="J":
print("ABCDEFGHIKLMNOPQRSTUVWXYZ")
elif IN=="k":
print("ABCDEFGHIJLMNOPQRSTUVWXYZ")
elif IN=="K":
print("ABCDEFGHIJLMNOPQRSTUVWXYZ")
elif IN=="l":
print("ABCDEFGHIJKMNOPQRSTUVWXYZ")
elif IN=="L":
print("ABCDEFGHIJKMNOPQRSTUVWXYZ")
elif IN=="m":
print("ABCDEFGHIJKLNOPQRSTUVWXYZ")
elif IN=="M":
print("ABCDEFGHIJKLNOPQRSTUVWXYZ")
elif IN=="n":
print("ABCDEFGHIJKLMOPQRSTUVWXYZ")
elif IN=="N":
print("ABCDEFGHIJKLMOPQRSTUVWXYZ")
elif IN=="o":
print("ABCDEFGHIJKLMNPQRSTUVWXYZ")
elif IN=="O":
print("ABCDEFGHIJKLMNPQRSTUVWXYZ")
elif IN=="p":
print("ABCDEFGHIJKLMNOQRSTUVWXYZ")
elif IN=="P":
print("ABCDEFGHIJKLMNOQRSTUVWXYZ")
elif IN=="q":
print("ABCDEFGHIJKLMNOPRSTUVWXYZ")
elif IN=="Q":
print("ABCDEFGHIJKLMNOPRSTUVWXYZ")
elif IN=="r":
print("ABCDEFGHIJKLMNOPQSTUVWXYZ")
elif IN=="R":
print("ABCDEFGHIJKLMNOPQSTUVWXYZ")
elif IN=="s":
print("ABCDEFGHIJKLMNOPQRTUVWXYZ")
elif IN=="S":
print("ABCDEFGHIJKLMNOPQRTUVWXYZ")
elif IN=="t":
print("ABCDEFGHIJKLMNOPQRSUVWXYZ")
elif IN=="T":
print("ABCDEFGHIJKLMNOPQRSUVWXYZ")
elif IN=="u":
print("ABCDEFGHIJKLMNOPQRSTVWXYZ")
elif IN=="U":
print("ABCDEFGHIJKLMNOPQRSTVWXYZ")
elif IN=="v":
print("ABCDEFGHIJKLMNOPQRSTUWXYZ")
elif IN=="V":
print("ABCDEFGHIJKLMNOPQRSTUWXYZ")
elif IN=="w":
print("ABCDEFGHIJKLMNOPQRSTUVXYZ")
elif IN=="W":
print("ABCDEFGHIJKLMNOPQRSTUVXYZ")
elif IN=="x":
print("ABCDEFGHIJKLMNOPQRSTUVWYZ")
elif IN=="X":
print("ABCDEFGHIJKLMNOPQRSTUVWYZ")
elif IN=="y":
print("ABCDEFGHIJKLMNOPQRSTUVWXZ")
elif IN=="Y":
print("ABCDEFGHIJKLMNOPQRSTUVWXZ")
elif IN=="z":
print("ABCDEFGHIJKLMNOPQRSTUVWXY")
elif IN=="Z":
print("ABCDEFGHIJKLMNOPQRSTUVWXY")
else:
print("One number at a time bud")
pass
I understand you probably worked hard on your project but sadly I think that it might be a bit too minimalistic to be able to generate encrypted text. What your code is currently doing is just, as you said, able to print 1 digit encryption.
Sadly, my knowledge with python has decreased but a simple google might be able to help you, which I had a quick look for so I hope this helps! http://www.dlitz.net/software/pycrypto/ This should hopefully help you out, it also provides you with a decrypter. if needs be,
I got this from their documents,
>>> from Crypto.Cipher import DES
>>> obj=DES.new('abcdefgh', DES.MODE_ECB)
>>> plain="Guido van Rossum is a space alien."
>>> len(plain)
34
>>> obj.encrypt(plain)
Traceback (innermost last):
File "<stdin>", line 1, in ?
ValueError: Strings for DES must be a multiple of 8 in length
>>> ciph=obj.encrypt(plain+'XXXXXX')
>>> ciph
'\021,\343Nq\214DY\337T\342pA\372\255\311s\210\363,\300j\330\250\312\347\342I\3215w\03561\303dgb/\006'
>>> obj.decrypt(ciph)
'Guido van Rossum is a space alien.XXXXXX'
Just for fun:
from string import ascii_uppercase
while True:
print("Input letters you would like to encrypt")
IN= input().upper()
if IN.upper() in ascii_uppercase:
print(ascii_uppercase.replace(IN, ''))
it looks like you're trying to return the complement of the roman alphabet with respect to the letters provided.
There are a few ways to do this:
from string import ascii_uppercase
def reduce_complement_alpha(letters):
res = reduce(lambda letter: alphabet.replace(letter, ''), letters.upper(), ascii_uppercase)
return res
def set_complement_letters(letters):
res = ''.join(sorted(set(ascii_upper) - set(letters.upper())))
return res
def filter_complement_letters(letters):
res = ''.join(filter(lambda l: l not in letters.upper(), ascii_uppercase))
return res
Those are just a few examples :) The first feature O(n log n) time complexity but in practice since your n is very small it doesn't matter, while the last one has a linear O(n) time complexity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.