How does one unit test a non-deterministic encryption function?

I am trying to override a non-deterministic encryption function from javascript to java. However, I noticed that the output of the function is different every time. However, whenever I decrypt the output, it always returns the source text.

For instance:

word: hello

encrypted :? Hx? 631ffe50353ddda632a7e8fa11136d6ffaa584eb43b34c96005b6256f9dc 4121c7a8545d79887b900672e5870d702441? H

decrypted: hello

word: hello

encrypted :? Hx? dfea4d1d30ebd5fc871c7c92d0230baf9e5298b19c3cfa0770fe2d2035f8 dad0116f2963b115c85c9d4725be505fca54? H

decrypted: hello

etc....

In unit test, this, as I can imagine, is also to implement the decryption function in java and then decrypt the output of the encryption function. If decryption gives the source, then encryption is correct.

For instance:

encrypted = Encrypt_text(word); assertEquals(word,Decrypt_text(encrypted); 

Any other suggestions ...?

+4
source share
2 answers

It is better to use the original decryption function to test your encryption function, rather than a new decryption routine. If you write both and use them to check each other, you will check the rounding of the data, but you will not check the intermediate result.

You can use Mozilla Rhino to run the Javascript decrypt routine: http://www.mozilla.org/rhino/

+2
source

If you are not interested in encrypted form, then the statements are just perfect.

+1
source

All Articles