package de.egga;

import org.junit.Test;

import java.util.List;
import java.util.Random;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

public class CesarCipherTest {

    Random random = new Random();
    List<Character> characters = asList('A', 'B', 'C', 'N', 'O', 'P');

    @Test
    public void encrypt_should_change_the_plaintext() {

        for (int i = 0; i < 100000; i++) {
            int stringLength = random.nextInt(10);
            String plaintext = createRandomString(characters, stringLength);

            String ciphertext = encrypt(plaintext);
            assertThat(ciphertext).isNotEqualTo(plaintext);
        }
    }

    @Test
    public void encrypting_twice_should_return_the_plaintext() {

        for (int i = 0; i < 100000; i++) {
            int stringLength = random.nextInt(10);
            String plaintext = createRandomString(characters, stringLength);

            String ciphertext = encrypt(encrypt(plaintext));
            assertThat(ciphertext).isEqualTo(plaintext);
        }
    }

    private String createRandomString(List<Character> characters, int stringLength) {
        String randomString = "";
        for (int j = 0; j < stringLength; j++) {
            randomString += characters.get(random.nextInt(characters.size()));
        }
        return randomString;
    }

    private String encrypt(String plaintext) {

        if (plaintext.endsWith("something")) {
            return plaintext.replace("something", "");
        }
        return plaintext + "something";
    }
}
@@ -461,33 +461,40 @@
 ength = 
-r
+getR
 andom
-.nextInt(10
+NotEmptyString(
 );%0A     
@@ -849,25 +849,32 @@
 h = 
-r
+getR
 andom
-.nextInt(10
+NotEmptyString(
 );%0A 
@@ -1077,32 +1077,507 @@
        %7D%0A    %7D%0A%0A
+    @Test%0A    public void ciphertext_should_not_contain_the_plaintext() %7B%0A%0A        for (int i = 0; i %3C 100000; i++) %7B%0A            int stringLength = getRandomNotEmptyString();%0A            String plaintext = createRandomString(characters, stringLength);%0A%0A            String ciphertext = encrypt(plaintext);%0A            assertThat(ciphertext).doesNotContain(plaintext);%0A        %7D%0A    %7D%0A%0A    private int getRandomNotEmptyString() %7B%0A        return random.nextInt(10) + 1;%0A    %7D%0A%0A
     private Stri
@@ -1905,56 +1905,108 @@
 ) %7B%0A
-%0A        if (plaintext.endsWith(%22something%22
+        String ciphertext = %22%22;%0A%0A        for (char plaintextCharacter : plaintext.toCharArray(
 )) %7B%0A
+%0A
     
@@ -2017,99 +2017,279 @@
     
-return plaintext.replace(%22something%22, %22%22);%0A        %7D%0A        return plaintext + %22something%22
+int offset = plaintextCharacter - 'A';%0A            int shift = offset + 13;%0A            int cipherOffset = shift %25 26;%0A%0A            char ciphertextCharacter = (char) ('A' + cipherOffset);%0A            ciphertext += ciphertextCharacter;%0A        %7D%0A%0A        return ciphertext
 ;%0A  

ciphertext does not contain plaintext