Encrypt string in Python

后端 未结 6 987
孤街浪徒
孤街浪徒 2021-01-06 11:29

I need to encrypt a small string in Python. Is it possible to use a secret key to encrypt the string? Is there a good way to do this and achieve a reasonable encryption leve

6条回答
  •  梦谈多话
    2021-01-06 12:14

    I recently created a piece of code that does pretty much what your saying. It takes a codeword such as 'abc'gets the values (1, 2, 3) and then adds them to each letter in the word to encrypt. So if 'abc' was the codeword and 'bcd' the text to encrypt. (1+2 =3 2+3 =5 and 3+4 = 7) so the output would then be 'ceg'

    codeword = input('Enter codeword : ')
    codeword = codeword.replace(" ", "")  
    
    encrypt = input('Enter text to encrypt : ')
    encrypt = encrypt.replace(" ", "")
    
    j = 0
    for i in codeword:
        print(chr(ord(encrypt[j])+ ord(codeword[j])-96))
        j+=1
    

提交回复
热议问题