1

Good Day Everybody! is there a way to solve the decoding problem after passing the keys, the code working fine with encrypted and decrypted but once i start select the publick key from data base shows me this problem. i have change the data type everything good different error in same line plain = [chr(pow(char ** key) % n) for char in ciphertext] the error im getting TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'

Suppose the data from database is

data=16502916241650364826125871181879125871246803291624295583281818234716503551129558335511291624181879181879246803125871295583304595291624291624181879295583181496181496184182295114292940

key=117535
n=365867
private_key=113503
p=643
q=569

it's suppose to give me out put this: b7bcd0d379f2b5957003d947709¢Ó

the decryption code :

def decrypt(nn,pk, ciphertext):
    #Unpack the key into its components

    n=nn
    key=pk
    #Generate the plaintext based on the ciphertext and key using a^b mod m
    plain = [chr((ord(char) ** key) % n) for char in ciphertext]
    #Return the array of bytes as a string
    return ''.join(plain)

if __name__ == '__main__':
    '''
    Detect if the script is being run directly by the user
    '''

    print("Your public key is ", public ," and your private key is ", private)

      msg1=name 

xxc=decrypt(n, key, msg1)
    print(xxc)
    print("\n")

in the end i'm sending the result of encrypted name is enc_name) and the public pair key picc and picc2

i have try change the data type of pk1=int(231761) and pk2=int(399089) but not working at all, and try for str also same problem. i have seen several posts of same related problem but the solution not working in same my case , such like here and here andhere andhere andhere none of these solutions are working with me. i'm using python 3.6 spyder

Any suggestion! thanks all

1
  • To improve your RSA code, you may ask it CodeReview.SE, since it is working now. And don't forget to upvote and accept if the answers are useful and correct. This way people can see that your problem is solved with the answer. Commented Feb 22, 2020 at 15:22

1 Answer 1

0

char variable is string, so you need to convert it to int first. You can use ord() function for this:

plain = [chr((ord(char) ** key)  % n) for char in ciphertext]
Sign up to request clarification or add additional context in comments.

15 Comments

thanks sir, but now im getting this error 'TypeError: pow expected at least 2 arguments, got 1' ?? even im passing two arguments public and msg1
maybe you want this chr(pow(ord(char), key) % n)
@honey you should use or pow or ** not both at the same time.
@honey yes you should pass n value to encrypt and dectypt data.
ok sir, i think thats the problem i just pass only the public key, i will test it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.