For my class assignment we need to decrypt a message that used RSA Encryption. We were given code that should help us with the decryption, but its not helping.

def block_decode(x):
    output = ""
    i = BLOCK_SIZE+1    
    while i > 0:
        b1 = int(pow(95,i-1))
        y = int(x/b1) 
        i = i - 1
        x = x - y*b1
        output = output + chr(y+32)
    return output

I'm not great with python yet but it looks like it is doing something one character at a time. What really has me stuck is the data we were given. Can't figure out where or how to store it or if it is really decrypted data using RSA. below are just 3 lines of 38 lines some lines have ' or " or even multiple.

FWfk ?0oQ!#|eO Wgny 1>a^ 80*^!(l{4! 3lL qj'b!.9#'!/s2_
!BH+V YFKq _@:X &?A8 j_p< 7\[0 la.[ a%}b E`3@ d3N? ;%FW
 KyYM!"4Tz yuok J;b^!,V4) \JkT .E[i i-y* O~$? o*1u d3N?

How do I get this into a string list?

有帮助吗?

解决方案

You are looking for the function ord which is a built-in function that

Returns the integer ordinal of a one-character string.

So for instance, you can do:

my_file = open("file_containing_encrypted_message")
data = my_file.read()

to read in the encrypted contents.

Then, you can iterate over each character doing

char_val = ord(each_character)
block_decode(char_val)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top