Home > other >  Python is a small white for help
Python is a small white for help

Time:09-25


[problem description] translation password, for the sake of confidentiality, often do not use clear, and with the ciphertext, namely according to certain rules to convert character to another character, the addressee is transformed from the original characters by opposite pattern, rules for the program: letter ASCII plus 5, other characters, to encrypt the original, and display the ciphertext, letters of the last five plus five is not letter, processing rules for loop into the top five, such as "X" cipher for the "C",

[sample input]

Both please input text: I love haha.
[sample output]

N qtaj MFMF.

[example] word () function is used to return the corresponding ASCII characters, CRH () is mainly used to said ASCII characters

CodePudding user response:

 
Def text_encrypt (plaintext) :
Ciphertext=[]
For char in plaintext:
If char. Isalpha () : # if letter
If (a 'v' & lt;=char & lt;='z') or (' V '& lt;=char & lt;='Z') :
Ciphertext. Append (CRH (word (char) - 21))
The else:
Ciphertext. Append (CRH (word (char) + 5))
Else: # if not the letter remain unchanged
Ciphertext. Append (char)
Return "". Join (ciphertext)

If __name__=="__main__ ':
# txt1='I love haha
# txt2='vwxyz, vwxyz'
TXT=input (' both Please input text: ')
Cipher=text_encrypt (TXT)
Print (f "Encrypted text is: {cipher}")

CodePudding user response:

Or so to:
 
Def text_encrypt (plaintext) :
Ciphertext=[]
For char in plaintext:
If char. Isalpha () : # if letter
Char_ascii=word (char) + 5 # character ASCII first unified plus 5
If (a 'v' & lt;=char & lt;='z') or (' V '& lt;=char & lt;='Z') :
Char_ascii -=26 # according to the displacement condition reset letter
Ciphertext. Append (CRH (char_ascii))
Else: # if not the letter remain unchanged
Ciphertext. Append (char)
Return '. Join (ciphertext)

If __name__=="__main__ ':
TXT=input (' both Please input text: ')
Cipher=text_encrypt (TXT)
Print (f 'Encrypted text is: {cipher}')
  • Related