I am using a tutorial for RSA implementation from this site: https://sahandsaba.com/cryptography-rsa-part-1.html
They use this function for encryption:
def power(x, m, n):
"""Calculate x^m modulo n using O(log(m)) operations."""
a = 1
while m > 0:
if m % 2 == 1:
a = (a * x) % n
x = (x * x) % n
m //= 2
return a
def rsa_encrypt(message, n, e):
return modular.power(message, e, n)
and then he encrypts a number:
>>> message = 123
>>> cipher = rsa_encrypt(message, n, e)
How do I encrypt entire String though? I want to encrypt string generated by a hash using this implementation.
ord('B')- value which is an integer. build a chain that converstsstring -> ord -> rsa and rsa -> ord -> string- Hashes are normally not reversable, so you will only be able to restore the hash - not the original string.