Some crypto for starters

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3. import static org.junit.Assert.*;
  4. public class ROT13Test {
  5. @Test
  6. public void rotateStringTest0() {
  7. // Given
  8. String s1 = "ABCDEF";
  9. String s2 = "ABCDEF";
  10. // When
  11. ROT13 cipher = new ROT13();
  12. String actual = cipher.rotate(s1, 'A');
  13. // Then
  14. assertTrue(actual.equals(s2));
  15. }
  16. @Test
  17. public void rotateStringTest1() {
  18. // Given
  19. String s1 = "ABCDEF";
  20. String s2 = "DEFABC";
  21. // When
  22. ROT13 cipher = new ROT13();
  23. String actual = cipher.rotate(s1, 'D');
  24. // Then
  25. assertTrue(actual.equals(s2));
  26. }
  27. @Test
  28. public void rotateStringTest2() {
  29. // Given
  30. String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  31. String s2 = "NOPQRSTUVWXYZABCDEFGHIJKLM";
  32. // When
  33. ROT13 cipher = new ROT13();
  34. String actual = cipher.rotate(s1, 'N');
  35. System.out.println(s1);
  36. System.out.println(actual);
  37. // Then
  38. assertTrue(actual.equals(s2));
  39. }
  40. @Test
  41. public void cryptTest1() {
  42. // Given
  43. ROT13 cipher = new ROT13('a', 'n');
  44. String Q1 = "Why did the chicken cross the road?";
  45. String A1 = "Jul qvq gur puvpxra pebff gur ebnq?";
  46. String Q2 = "Gb trg gb gur bgure fvqr!";
  47. String A2 = "To get to the other side!";
  48. // When
  49. String actual = cipher.encrypt(Q1);
  50. System.out.println(Q1);
  51. System.out.println(A1);
  52. // Then
  53. assertTrue(actual.equals(A1));
  54. // When
  55. String actual2 = cipher.decrypt(Q2);
  56. System.out.println(Q2);
  57. System.out.println(A2);
  58. // Then
  59. assertTrue(actual2.equals(A2));
  60. }
  61. @Test
  62. public void cryptTest2() {
  63. // Given
  64. ROT13 cipher = new ROT13('a', 'n');
  65. String Q1 = "Why did the chicken cross the road?";
  66. System.out.println(Q1);
  67. // When
  68. String actual = cipher.crypt(cipher.crypt(Q1));
  69. System.out.println(actual);
  70. // Then
  71. assertTrue(actual.equals(Q1));
  72. }
  73. }