Some crypto for starters

AtbashCipherTest.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3. import java.io.BufferedReader;;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. public class AtbashCipherTest {
  7. @Test
  8. public void testCipher() {
  9. AtbashCipher cipher = new AtbashCipher();
  10. String test = "ABCDEF";
  11. String exp = "ZYXWVU";
  12. String actual = cipher.cipher(test);
  13. Assert.assertEquals(exp, actual);
  14. }
  15. @Test
  16. public void testFiles() throws IOException {
  17. AtbashCipher cipher = new AtbashCipher();
  18. String inputFile = "sonnet18.txt";
  19. String outputTest = "testFileOutput.txt";
  20. String decryptTest = "decryptedTestFile.txt";
  21. cipher.cipherFile(inputFile, outputTest);
  22. cipher.cipherFile(outputTest, decryptTest);
  23. BufferedReader bROriginal = new BufferedReader(new FileReader(inputFile));
  24. BufferedReader bRDecyphered = new BufferedReader(new FileReader(decryptTest));
  25. String originalLine;
  26. String decrpytLine;
  27. while ((originalLine = bROriginal.readLine()) != null) {
  28. decrpytLine = bRDecyphered.readLine();
  29. Assert.assertEquals(originalLine, decrpytLine);
  30. }
  31. }
  32. }