java - Convert plaintext to perform elgamal encryption -


hi i'm writing program in java test variant of elgamal encryption, problem not encryption/decryption chain itself, how perform operations on input given: text file. have text file words in (for example content can be: "hello world, test") , need perform numeric operations on them this:

ciphertext= (message * y) mod p

where y , p 2 biginteger. tried conversion chain: (reading 1 string @ time):

string->hexadecimal->decimal

then perform encrypt operation, , inverse:

decimal->hexadecimal->string

but doesn't work time (i'm investigate on issue). fixed.

my question is, there better way this? reading byte array's i'm not sure how use them.

[i can post example of encryption/decryption chain if needed]

biginteger has constructor taking byte array argument.

any string can converted byte array, without loss, using (for example), utf-8 encoding:

byte[] bytes = string.getbytes(standardcharsets.utf_8);  

combine both, , have easy way transform string bigdecimal.

for reverse operation, use biginteger.tobytearray(), , new string(bytes, standardcharsets.utf_8).


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -