Issue
Good afternoon,
(Im beginner programmer)
I have a small problem in Python. Im trying to write a programme with GUI, that has got 4 user inputs. The first input is key a
, second is key b
, third is for text to encrypt
and forth is for text to decrypt
. For encrypting the programme is using Affine Cipher
.
I will show you my problem on example: User enters key a
as 1
, key b
as 3
and text for encrypt
enters letter D
. The programme output on console will be letter G
, that is good but when user puts more letters like DE
or some words, there will be an error that says 'DE' is not in list
and if I try to put the user input to list, it will say the same thing but this time, the error will be saying 'D' 'E' is not in list
and even cant encrypt only one letter.
So the problem is that programme can compare one letter from user input with alphabet and get index of this letter and encrypt it but when there are more letters it cant. Thank you for your help!
def Encrypt_Input (input,key_a,key_b):
input = self.User_Input.upper()
No_Diacritic = unidecode.unidecode(input)
alphabet = list(string.ascii_uppercase)
input_index = alphabet.index(No_Diacritic)
Encryption = ((int(self.key_a)*input_index)+int(self.key_b))%26
Encrypted = alphabet[Encyption]
print(Encrypted)
return Encrypted
Solution
You can use a wrapper function that iterates the text letter by letter (by using for loop), and for each letter, it uses your function and concatenates the outputs.
Answered By - OrpazFishel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.