Search code examples
c#encryption

How to encrypt the data without exceed size of original data?


My question is simple I am expecting encryption algorithm,

I need to encrypt a original data(text etc.) that encrypted data size should be same size of original data size? Share your idea kindly?

Example: Original data is "test" (so length of text is 4) the expected encrypted data should be like this "etst" (so length is 4).


Solution

  • This is not always possible, especially with short amounts of data. I am pretty sure that all the standard algorithms work on "blocks", which are usually the length of the key. So unless you go with a really weak key, or use something weak like substitution cipher or caesar cipher your encrypted data could end up a little longer than the original.

    Actually, according to this page you can use a stream cipher and get encrypted text that is the same size as the input. The example given is RC4.