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
Post a Comment