c# - Good ways of converting letters to numbers in naive RSA implementation? -
i'm implementing short rsa program , have code:
private string encrypt(string data) { biginteger dataasbiginteger = new biginteger(encoding.utf8.getbytes(data)); biginteger remainder = biginteger.modpow(dataasbiginteger, exponente, calculatepublickey()); return convert.tobase64string(remainder.tobytearray()); } private string decrypt(string data) { biginteger dataasbiginteger = new biginteger(convert.frombase64string(data)); biginteger remainder = biginteger.modpow(dataasbiginteger, calculateprivatekey(), calculatepublickey()); return encoding.utf8.getstring(remainder.tobytearray()); } unfortunately, seem getting weird ascii values result. tried using numbers instead of text , decrypt(encrypt(number)) == number know algorithm fine think messing because of converting , byte arrays , performing operations on them.
if didn't work thinking of better idea formula of converting letters numbers. can't a = 1, b = 2, etc. because 11 ambiguous k (11th letter). maybe if each letter's position (a = 1, b = 2, etc.) first multiplied 10 , know next letter began @ non-zero value?
is advisable or can byte arrays salvaged?
in principle scheme should work, long resulting biginteger not negative or larger modulus.
if cryptographically secure rsa implementation such oaep used need subtract overhead of padding. though should encrypt symmetric key , use hybrid cryptography allow arbitrary message sizes.
Comments
Post a Comment