Strings
Ciphers
Fundamentals
Cryptography
Algorithms
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import java.util.List; import java.util.Random; import java.util.stream.Collectors; class SolutionTest { @Test void basicTest() { assertEquals("moqik", Kata.encode("abcde", "abcde")); assertEquals("abcde", Kata.decode("moqik", "abcde")); assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE")); assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE")); assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH")); assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH")); assertEquals("ikhwmvi", Kata.encode("deargod", "fgh")); assertEquals("deargod", Kata.decode("ikhwmvi", "fgh")); assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME")); assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME")); } @Test void specialCasesTest() { assertEquals("", Kata.encode("", "")); assertEquals("TernaryLove", Kata.encode("TernaryLove", "")); assertEquals("", Kata.encode("", "abcde")); assertEquals("", Kata.encode(null, null)); assertEquals("", Kata.encode("", null)); assertEquals("", Kata.encode(null, "")); assertEquals("IntelliJCrew",Kata.encode("IntelliJCrew", null)); assertEquals("", Kata.encode(null, "IlikeBreaksInForLoops")); } @Test void fullTestSimpleOverflow() { assertEquals("CEEpB", Kata.encode("turbo", "TUXON")); assertEquals("turbo", Kata.decode("CEEpB", "TUXON")); assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh")); assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh")); assertEquals("IKM", Kata.encode("xyz", "ijklmn")); assertEquals("xyz", Kata.decode("IKM", "ijklmn")); assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA")); assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA")); assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID")); assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID")); } @Test void fullTestIntermediateOverflow() { assertEquals("rhCRDjxXEVyfu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT")); assertEquals("hOmEsWeEtHoMe", Kata.decode("rhCRDjxXEVyfu", "nOtSoSwEeT")); assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS")); assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS")); assertEquals("lyynmpA", Kata.encode("Zumbido", "wow")); assertEquals("Zumbido", Kata.decode("lyynmpA", "wow")); } private Random random = new Random(); String generateString(int lowerBound, int upperBound) { return java.util.stream.IntStream.rangeClosed(random.nextInt(lowerBound + 1), random.nextInt(upperBound + 1)) .mapToObj(i -> random.nextInt(2) == 0 ? random.nextInt(65, 91) : random.nextInt(97, 123)) .collect(StringBuilder::new, (sb, code) -> sb.append((char) code.intValue()), StringBuilder::append) .toString(); } String generatePhrase(int lowerBound, int upperBound) { return generateString(lowerBound, upperBound); } String generateKey(int lowerBound, int upperBound) { return generateString(lowerBound, upperBound); } @RepeatedTest(1500) void randomEasyModeTest() { String phrase = generatePhrase(0, 100); String key = generateKey(0, 100); assertEquals(Kata.encode(phrase, key), encode(phrase, key)); assertEquals(Kata.decode(phrase, key), decode(phrase, key)); } @RepeatedTest(1000) void randomHardModeTest() { String phrase = generatePhrase(1000, 15000); String key = generateKey(1000, 15000); assertEquals(Kata.encode(phrase, key), encode(phrase, key)); assertEquals(Kata.decode(phrase, key), decode(phrase, key)); } @RepeatedTest(50) void randomGodModeTest() { String phrase = generatePhrase(89000, 90000); String key = generateKey(79000, 80000); assertEquals(Kata.encode(phrase, key), encode(phrase, key)); assertEquals(Kata.decode(phrase, key), decode(phrase, key)); } // [[ A N S W E R ]] // <<-CONSTANTS->> private static final int UpperCase_LOWER_LIMIT = 65; private static final int UpperCase_UPPER_LIMIT = 90; private static final int LowerCase_LOWER_LIMIT = 97; private static final int LowerCase_UPPER_LIMIT = 122; private static final int INTERMEDIATE_OFFSET = LowerCase_LOWER_LIMIT - UpperCase_UPPER_LIMIT - 1; // <<-METHODS->> private static int getLastDigit(final int digit) { String str = String.valueOf(digit); str = str.substring(str.length() - 1, str.length()); return Integer.valueOf(str); } private static List<Integer> getEncryptationOffsets(String key) { return key.chars() .map(n -> getLastDigit(n) + key.length()) .boxed() .toList(); } private static List<Integer> getPhraseChars(String phrase) { return phrase.chars() .boxed() .collect(Collectors.toList()); } private static String parseChars(List<Integer> translation) { return translation.stream() .map(n -> (char) n.intValue()) .map(c -> Character.toString(c)) .collect(Collectors.joining()); } public static String encode(String phrase, String key) { if (phrase == null || phrase.isEmpty()) return ""; if (key == null || key.isEmpty()) return phrase; List<Integer> offsets = getEncryptationOffsets(key); List<Integer> phraseChars = getPhraseChars(phrase); List<Integer> traduction = new java.util.ArrayList<>(); for (int i = 0; i < phrase.length(); i++) { int keyIndex = i % offsets.size(); int current = phraseChars.get(i); int result = current + offsets.get(keyIndex); if (current <= UpperCase_UPPER_LIMIT && result >= LowerCase_LOWER_LIMIT) { int offset = result - UpperCase_UPPER_LIMIT; result = LowerCase_LOWER_LIMIT + offset - 1; } if (result > UpperCase_UPPER_LIMIT && result < LowerCase_LOWER_LIMIT) { result += INTERMEDIATE_OFFSET; } else if (result > LowerCase_UPPER_LIMIT) { result = result - LowerCase_UPPER_LIMIT + UpperCase_LOWER_LIMIT - 1; } traduction.add(result); } return parseChars(traduction); } public static String decode(String phrase, String key) { if (phrase == null || phrase.isEmpty()) return ""; if (key == null || key.isEmpty()) return phrase; List<Integer> offsets = getEncryptationOffsets(key); List<Integer> phraseChars = getPhraseChars(phrase); List<Integer> traduction = new java.util.ArrayList<>(); for (int i = 0; i < phrase.length(); i++) { int keyIndex = i % offsets.size(); int current = phraseChars.get(i); int result = current - offsets.get(keyIndex); if (current >= LowerCase_LOWER_LIMIT && result <= UpperCase_UPPER_LIMIT) { int offset = LowerCase_LOWER_LIMIT - result; result = UpperCase_UPPER_LIMIT - offset + 1; } if (result < LowerCase_LOWER_LIMIT && result > UpperCase_UPPER_LIMIT) { result -= INTERMEDIATE_OFFSET; } else if (result < UpperCase_LOWER_LIMIT) { int offset = UpperCase_LOWER_LIMIT - result; result = LowerCase_UPPER_LIMIT - offset + 1; } traduction.add(result); } return parseChars(traduction); } }
- import static org.junit.jupiter.api.Assertions.*;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import java.util.List;
- import java.util.Random;
- import java.util.stream.Collectors;
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals("moqik", Kata.encode("abcde", "abcde"));
- assertEquals("abcde", Kata.decode("moqik", "abcde"));
- assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE"));
- assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE"));
- assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH"));
- assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH"));
- assertEquals("ikhwmvi", Kata.encode("deargod", "fgh"));
- assertEquals("deargod", Kata.decode("ikhwmvi", "fgh"));
- assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME"));
- assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME"));
- }
- @Test
- void specialCasesTest() {
assertEquals("", Kata.encode("", ""));assertEquals("TernaryLove", Kata.encode("TernaryLove", ""));assertEquals("", Kata.encode(null, "abcde"));assertEquals("", Kata.encode("", null));- assertEquals("", Kata.encode("", ""));
- assertEquals("TernaryLove", Kata.encode("TernaryLove", ""));
- assertEquals("", Kata.encode("", "abcde"));
- assertEquals("", Kata.encode(null, null));
- assertEquals("", Kata.encode("", null));
- assertEquals("", Kata.encode(null, ""));
- assertEquals("IntelliJCrew",Kata.encode("IntelliJCrew", null));
- assertEquals("", Kata.encode(null, "IlikeBreaksInForLoops"));
- }
- @Test
- void fullTestSimpleOverflow() {
- assertEquals("CEEpB", Kata.encode("turbo", "TUXON"));
- assertEquals("turbo", Kata.decode("CEEpB", "TUXON"));
- assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh"));
- assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh"));
- assertEquals("IKM", Kata.encode("xyz", "ijklmn"));
- assertEquals("xyz", Kata.decode("IKM", "ijklmn"));
- assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA"));
- assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA"));
- assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID"));
- assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID"));
- }
- @Test
- void fullTestIntermediateOverflow() {
- assertEquals("rhCRDjxXEVyfu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT"));
- assertEquals("hOmEsWeEtHoMe", Kata.decode("rhCRDjxXEVyfu", "nOtSoSwEeT"));
- assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS"));
- assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS"));
- assertEquals("lyynmpA", Kata.encode("Zumbido", "wow"));
- assertEquals("Zumbido", Kata.decode("lyynmpA", "wow"));
- }
- private Random random = new Random();
- String generateString(int lowerBound, int upperBound) {
- return java.util.stream.IntStream.rangeClosed(random.nextInt(lowerBound + 1), random.nextInt(upperBound + 1))
- .mapToObj(i -> random.nextInt(2) == 0 ? random.nextInt(65, 91) : random.nextInt(97, 123))
- .collect(StringBuilder::new, (sb, code) -> sb.append((char) code.intValue()), StringBuilder::append)
- .toString();
- }
- String generatePhrase(int lowerBound, int upperBound) {
- return generateString(lowerBound, upperBound);
- }
- String generateKey(int lowerBound, int upperBound) {
- return generateString(lowerBound, upperBound);
- }
- @RepeatedTest(1500)
- void randomEasyModeTest() {
- String phrase = generatePhrase(0, 100);
- String key = generateKey(0, 100);
- assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- }
- @RepeatedTest(1000)
- void randomHardModeTest() {
- String phrase = generatePhrase(1000, 15000);
- String key = generateKey(1000, 15000);
- assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- }
- @RepeatedTest(50)
- void randomGodModeTest() {
- String phrase = generatePhrase(89000, 90000);
- String key = generateKey(79000, 80000);
- assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- }
- // [[ A N S W E R ]]
- // <<-CONSTANTS->>
- private static final int UpperCase_LOWER_LIMIT = 65;
- private static final int UpperCase_UPPER_LIMIT = 90;
- private static final int LowerCase_LOWER_LIMIT = 97;
- private static final int LowerCase_UPPER_LIMIT = 122;
- private static final int INTERMEDIATE_OFFSET = LowerCase_LOWER_LIMIT - UpperCase_UPPER_LIMIT - 1;
- // <<-METHODS->>
- private static int getLastDigit(final int digit) {
- String str = String.valueOf(digit);
- str = str.substring(str.length() - 1, str.length());
- return Integer.valueOf(str);
- }
- private static List<Integer> getEncryptationOffsets(String key) {
- return key.chars()
- .map(n -> getLastDigit(n) + key.length())
- .boxed()
- .toList();
- }
- private static List<Integer> getPhraseChars(String phrase) {
- return phrase.chars()
- .boxed()
- .collect(Collectors.toList());
- }
- private static String parseChars(List<Integer> translation) {
- return translation.stream()
- .map(n -> (char) n.intValue())
- .map(c -> Character.toString(c))
- .collect(Collectors.joining());
- }
- public static String encode(String phrase, String key) {
- if (phrase == null || phrase.isEmpty()) return "";
- if (key == null || key.isEmpty()) return phrase;
- List<Integer> offsets = getEncryptationOffsets(key);
- List<Integer> phraseChars = getPhraseChars(phrase);
- List<Integer> traduction = new java.util.ArrayList<>();
- for (int i = 0; i < phrase.length(); i++) {
- int keyIndex = i % offsets.size();
- int current = phraseChars.get(i);
- int result = current + offsets.get(keyIndex);
- if (current <= UpperCase_UPPER_LIMIT && result >= LowerCase_LOWER_LIMIT) {
- int offset = result - UpperCase_UPPER_LIMIT;
- result = LowerCase_LOWER_LIMIT + offset - 1;
- }
- if (result > UpperCase_UPPER_LIMIT && result < LowerCase_LOWER_LIMIT) {
- result += INTERMEDIATE_OFFSET;
- } else if (result > LowerCase_UPPER_LIMIT) {
- result = result - LowerCase_UPPER_LIMIT + UpperCase_LOWER_LIMIT - 1;
- }
- traduction.add(result);
- }
- return parseChars(traduction);
- }
- public static String decode(String phrase, String key) {
- if (phrase == null || phrase.isEmpty()) return "";
- if (key == null || key.isEmpty()) return phrase;
- List<Integer> offsets = getEncryptationOffsets(key);
- List<Integer> phraseChars = getPhraseChars(phrase);
- List<Integer> traduction = new java.util.ArrayList<>();
- for (int i = 0; i < phrase.length(); i++) {
- int keyIndex = i % offsets.size();
- int current = phraseChars.get(i);
- int result = current - offsets.get(keyIndex);
- if (current >= LowerCase_LOWER_LIMIT && result <= UpperCase_UPPER_LIMIT) {
- int offset = LowerCase_LOWER_LIMIT - result;
- result = UpperCase_UPPER_LIMIT - offset + 1;
- }
- if (result < LowerCase_LOWER_LIMIT && result > UpperCase_UPPER_LIMIT) {
- result -= INTERMEDIATE_OFFSET;
- } else if (result < UpperCase_LOWER_LIMIT) {
- int offset = UpperCase_LOWER_LIMIT - result;
- result = LowerCase_UPPER_LIMIT - offset + 1;
- }
- traduction.add(result);
- }
- return parseChars(traduction);
- }
- }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
import java.util.List; import java.util.stream.Collectors; public class Kata { private static final int UPPERCASE_LOWERLIMIT = 65; private static final int UPPERCASE_UPPERLIMIT = 90; private static final int LOWERCASE_LOWERLIMIT = 97; private static final int LOWERCASE_UPPERLIMIT = 122; private static final int INTERMEDIATE_OFFSET = LOWERCASE_LOWERLIMIT-UPPERCASE_UPPERLIMIT-1; public static void main(String[] args) { System.out.println(decode("rhCRDjxXEVyfu", "nOtSoSwEeT")); } // <<-METHODS->> private static int getLastDigit(int n) { String str = String.valueOf(n); str = str.substring(str.length() - 1, str.length()); return Integer.valueOf(str); } public static String encode(String phrase, String key) { List<Integer> adds = key.chars() .map(n -> getLastDigit(n) + key.length()) .boxed() .toList(); List<Integer> phraseChars = phrase.chars() .boxed() .collect(Collectors.toList()); List<Integer> traduction = new java.util.ArrayList<>(); int j = 0; for (int i = 0; i < phrase.length(); i++) { if (j == adds.size()) j = 0; int actualChar=phraseChars.get(i); int result=adds.get(j)+actualChar; if(actualChar<=UPPERCASE_UPPERLIMIT&&result>=LOWERCASE_LOWERLIMIT) { int offset=result-UPPERCASE_UPPERLIMIT; result=LOWERCASE_LOWERLIMIT+offset-1; } if(result>UPPERCASE_UPPERLIMIT&&result<LOWERCASE_LOWERLIMIT) { result+=INTERMEDIATE_OFFSET; } else if(result>LOWERCASE_UPPERLIMIT) { result=result-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1; } traduction.add(result); j++; } return traduction.stream() .map(n -> (char) n.intValue()) .map(ch -> Character.toString(ch)) .collect(Collectors.joining()); } /*-----------------------------------------------------------------------------------*/ public static String decode(String phrase, String key) { List<Integer> adds = key.chars() .map(n -> getLastDigit(n) + key.length()) .boxed() .toList(); List<Integer> phraseChars = phrase.chars() .boxed() .collect(Collectors.toList()); List<Integer> traduction = new java.util.ArrayList<>(); int j = 0; for (int i = 0; i < phrase.length(); i++) { if (j == adds.size()) j = 0; int actualChar=phraseChars.get(i); int resulSum=actualChar-adds.get(j); if(actualChar>=LOWERCASE_LOWERLIMIT&&resulSum<=UPPERCASE_UPPERLIMIT) { int offset=LOWERCASE_LOWERLIMIT-resulSum; resulSum=UPPERCASE_UPPERLIMIT-offset+1; } if(resulSum<LOWERCASE_LOWERLIMIT&&resulSum>UPPERCASE_UPPERLIMIT) { resulSum-=INTERMEDIATE_OFFSET; } else if(resulSum<UPPERCASE_LOWERLIMIT) { int offset=UPPERCASE_LOWERLIMIT-resulSum; resulSum=LOWERCASE_UPPERLIMIT-offset+1; } traduction.add(resulSum); j++; } return traduction.stream() .map(n -> (char) n.intValue()) .map(ch -> Character.toString(ch)) .collect(Collectors.joining()); } }
- import java.util.List;
- import java.util.stream.Collectors;
- public class Kata {
- private static final int UPPERCASE_LOWERLIMIT = 65;
- private static final int UPPERCASE_UPPERLIMIT = 90;
- private static final int LOWERCASE_LOWERLIMIT = 97;
- private static final int LOWERCASE_UPPERLIMIT = 122;
private static final int UPPERTOLOWER_OFFSET = LOWERCASE_LOWERLIMIT-UPPERCASE_UPPERLIMIT-1;private static final int LOWERTOUPPER_OFFSET = LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1;- private static final int INTERMEDIATE_OFFSET = LOWERCASE_LOWERLIMIT-UPPERCASE_UPPERLIMIT-1;
- public static void main(String[] args) {
- System.out.println(decode("rhCRDjxXEVyfu", "nOtSoSwEeT"));
- }
- // <<-METHODS->>
- private static int getLastDigit(int n) {
- String str = String.valueOf(n);
- str = str.substring(str.length() - 1, str.length());
- return Integer.valueOf(str);
- }
- public static String encode(String phrase, String key) {
- List<Integer> adds = key.chars()
- .map(n -> getLastDigit(n) + key.length())
- .boxed()
- .toList();
- List<Integer> phraseChars = phrase.chars()
- .boxed()
- .collect(Collectors.toList());
- List<Integer> traduction = new java.util.ArrayList<>();
- int j = 0;
- for (int i = 0; i < phrase.length(); i++) {
- if (j == adds.size()) j = 0;
- int actualChar=phraseChars.get(i);
int resulSum=adds.get(j)+actualChar;if(actualChar<=UPPERCASE_UPPERLIMIT&&resulSum>=LOWERCASE_LOWERLIMIT) {int offset=resulSum-UPPERCASE_UPPERLIMIT;resulSum=LOWERCASE_LOWERLIMIT+offset-1;- int result=adds.get(j)+actualChar;
- if(actualChar<=UPPERCASE_UPPERLIMIT&&result>=LOWERCASE_LOWERLIMIT) {
- int offset=result-UPPERCASE_UPPERLIMIT;
- result=LOWERCASE_LOWERLIMIT+offset-1;
- }
if(resulSum>UPPERCASE_UPPERLIMIT&&resulSum<LOWERCASE_LOWERLIMIT) {resulSum+=UPPERTOLOWER_OFFSET;- if(result>UPPERCASE_UPPERLIMIT&&result<LOWERCASE_LOWERLIMIT) {
- result+=INTERMEDIATE_OFFSET;
- }
else if(resulSum>LOWERCASE_UPPERLIMIT) {resulSum=resulSum-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1;- else if(result>LOWERCASE_UPPERLIMIT) {
- result=result-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1;
- }
traduction.add(resulSum);- traduction.add(result);
- j++;
- }
- return traduction.stream()
- .map(n -> (char) n.intValue())
- .map(ch -> Character.toString(ch))
- .collect(Collectors.joining());
- }
- /*-----------------------------------------------------------------------------------*/
- public static String decode(String phrase, String key) {
return "";- List<Integer> adds = key.chars()
- .map(n -> getLastDigit(n) + key.length())
- .boxed()
- .toList();
- List<Integer> phraseChars = phrase.chars()
- .boxed()
- .collect(Collectors.toList());
- List<Integer> traduction = new java.util.ArrayList<>();
- int j = 0;
- for (int i = 0; i < phrase.length(); i++) {
- if (j == adds.size()) j = 0;
- int actualChar=phraseChars.get(i);
- int resulSum=actualChar-adds.get(j);
- if(actualChar>=LOWERCASE_LOWERLIMIT&&resulSum<=UPPERCASE_UPPERLIMIT) {
- int offset=LOWERCASE_LOWERLIMIT-resulSum;
- resulSum=UPPERCASE_UPPERLIMIT-offset+1;
- }
- if(resulSum<LOWERCASE_LOWERLIMIT&&resulSum>UPPERCASE_UPPERLIMIT) {
- resulSum-=INTERMEDIATE_OFFSET;
- }
- else if(resulSum<UPPERCASE_LOWERLIMIT) {
- int offset=UPPERCASE_LOWERLIMIT-resulSum;
- resulSum=LOWERCASE_UPPERLIMIT-offset+1;
- }
- traduction.add(resulSum);
- j++;
- }
- return traduction.stream()
- .map(n -> (char) n.intValue())
- .map(ch -> Character.toString(ch))
- .collect(Collectors.joining());
- }
- }
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import java.util.Random; class SolutionTest { @Test void basicTest() { assertEquals("moqik", Kata.encode("abcde", "abcde")); assertEquals("abcde", Kata.decode("moqik", "abcde")); assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE")); assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE")); assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH")); assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH")); assertEquals("ikhwmvi", Kata.encode("deargod", "fgh")); assertEquals("deargod", Kata.decode("ikhwmvi", "fgh")); assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME")); assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME")); } @Test void fullTestSimpleOverflow() { assertEquals("CEEpB", Kata.encode("turbo", "TUXON")); assertEquals("turbo", Kata.decode("CEEpB", "TUXON")); assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh")); assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh")); assertEquals("IKM", Kata.encode("xyz", "ijklmn")); assertEquals("xyz", Kata.decode("IKM", "ijklmn")); assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA")); assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA")); assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID")); assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID")); } @Test void fullTestIntermediateOverflow() { assertEquals("rhCRDjxXEVyfu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT")); assertEquals("hOmEsWeEtHoMe", Kata.decode("rhCRDjxXEVyfu", "nOtSoSwEeT")); assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS")); assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS")); assertEquals("lyynmpA", Kata.encode("Zumbido", "wow")); assertEquals("Zumbido", Kata.decode("lyynmpA", "wow")); } private String encode(String phrase, String key) { return ""; } private String decode(String phrase, String key) { return ""; } String generateString() { Random random = new Random(); byte[] buffer = new byte[random.nextInt(1501)]; random.nextBytes(buffer); return new String(buffer, java.nio.charset.Charset.forName("UTF-8")); } String generatePhrase() { return generateString(); } String generateKey() { return generateString(); } @RepeatedTest(100) void randomTest() { //String phrase = generatePhrase(); //String key = generateKey(); //assertEquals(Kata.encode(phrase, key), encode(phrase, key)); //assertEquals(Kata.decode(phrase, key), decode(phrase, key)); assertTrue(true); } }
- import static org.junit.jupiter.api.Assertions.*;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import java.util.Random;
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals("moqik", Kata.encode("abcde", "abcde"));
//assertEquals("abcde", Kata.decode("moqik", "abcde"));- assertEquals("abcde", Kata.decode("moqik", "abcde"));
- assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE"));
//assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE"));- assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE"));
- assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH"));
//assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH"));- assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH"));
- assertEquals("ikhwmvi", Kata.encode("deargod", "fgh"));
//assertEquals("deargod", Kata.decode("ikhwmvi", "fgh"));- assertEquals("deargod", Kata.decode("ikhwmvi", "fgh"));
- assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME"));
//assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME"));- assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME"));
- }
- @Test
- void fullTestSimpleOverflow() {
- assertEquals("CEEpB", Kata.encode("turbo", "TUXON"));
//assertEquals("turbo", Kata.decode("CEEpB", "TUXON"));- assertEquals("turbo", Kata.decode("CEEpB", "TUXON"));
- assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh"));
//assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh"));- assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh"));
- assertEquals("IKM", Kata.encode("xyz", "ijklmn"));
//assertEquals("xyz", Kata.decode("IKM", "ijklmn"));- assertEquals("xyz", Kata.decode("IKM", "ijklmn"));
- assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA"));
//assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA"));- assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA"));
- assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID"));
//assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID"));- assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID"));
- }
- @Test
- void fullTestIntermediateOverflow() {
- assertEquals("rhCRDjxXEVyfu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT"));
//assertEquals("hOmEsWeEtHoMe", Kata.decode("rhCRDjxXEVyfu", "nOtSoSwEeT"));- assertEquals("hOmEsWeEtHoMe", Kata.decode("rhCRDjxXEVyfu", "nOtSoSwEeT"));
- assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS"));
//assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS"));- assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS"));
- assertEquals("lyynmpA", Kata.encode("Zumbido", "wow"));
//assertEquals("Zumbido", Kata.decode("MyynmpA", "wow"));- assertEquals("Zumbido", Kata.decode("lyynmpA", "wow"));
- }
- private String encode(String phrase, String key) {
- return "";
- }
- private String decode(String phrase, String key) {
- return "";
- }
- String generateString() {
- Random random = new Random();
- byte[] buffer = new byte[random.nextInt(1501)];
- random.nextBytes(buffer);
- return new String(buffer, java.nio.charset.Charset.forName("UTF-8"));
- }
- String generatePhrase() {
- return generateString();
- }
- String generateKey() {
- return generateString();
- }
- @RepeatedTest(100)
- void randomTest() {
- //String phrase = generatePhrase();
- //String key = generateKey();
- //assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- //assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- assertTrue(true);
- }
- }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
import java.util.List; import java.util.stream.Collectors; public class Kata { private static final int UPPERCASE_LOWERLIMIT = 65; private static final int UPPERCASE_UPPERLIMIT = 90; private static final int LOWERCASE_LOWERLIMIT = 97; private static final int LOWERCASE_UPPERLIMIT = 122; private static final int UPPERTOLOWER_OFFSET = LOWERCASE_LOWERLIMIT-UPPERCASE_UPPERLIMIT-1; private static final int LOWERTOUPPER_OFFSET = LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1; // <<-METHODS->> private static int getLastDigit(int n) { String str = String.valueOf(n); str = str.substring(str.length() - 1, str.length()); return Integer.valueOf(str); } public static String encode(String phrase, String key) { List<Integer> adds = key.chars() .map(n -> getLastDigit(n) + key.length()) .boxed() .toList(); List<Integer> phraseChars = phrase.chars() .boxed() .collect(Collectors.toList()); List<Integer> traduction = new java.util.ArrayList<>(); int j = 0; for (int i = 0; i < phrase.length(); i++) { if (j == adds.size()) j = 0; int actualChar=phraseChars.get(i); int resulSum=adds.get(j)+actualChar; if(actualChar<=UPPERCASE_UPPERLIMIT&&resulSum>=LOWERCASE_LOWERLIMIT) { int offset=resulSum-UPPERCASE_UPPERLIMIT; resulSum=LOWERCASE_LOWERLIMIT+offset-1; } if(resulSum>UPPERCASE_UPPERLIMIT&&resulSum<LOWERCASE_LOWERLIMIT) { resulSum+=UPPERTOLOWER_OFFSET; } else if(resulSum>LOWERCASE_UPPERLIMIT) { resulSum=resulSum-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1; } traduction.add(resulSum); j++; } return traduction.stream() .map(n -> (char) n.intValue()) .map(ch -> Character.toString(ch)) .collect(Collectors.joining()); } public static String decode(String phrase, String key) { return ""; } }
- import java.util.List;
- import java.util.stream.Collectors;
- public class Kata {
- private static final int UPPERCASE_LOWERLIMIT = 65;
- private static final int UPPERCASE_UPPERLIMIT = 90;
- private static final int LOWERCASE_LOWERLIMIT = 97;
- private static final int LOWERCASE_UPPERLIMIT = 122;
- private static final int UPPERTOLOWER_OFFSET = LOWERCASE_LOWERLIMIT-UPPERCASE_UPPERLIMIT-1;
- private static final int LOWERTOUPPER_OFFSET = LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1;
- // <<-METHODS->>
- private static int getLastDigit(int n) {
- String str = String.valueOf(n);
- str = str.substring(str.length() - 1, str.length());
- return Integer.valueOf(str);
- }
- public static String encode(String phrase, String key) {
- List<Integer> adds = key.chars()
- .map(n -> getLastDigit(n) + key.length())
- .boxed()
- .toList();
- List<Integer> phraseChars = phrase.chars()
- .boxed()
- .collect(Collectors.toList());
- List<Integer> traduction = new java.util.ArrayList<>();
- int j = 0;
- for (int i = 0; i < phrase.length(); i++) {
- if (j == adds.size()) j = 0;
int resulSum=adds.get(j)+phraseChars.get(i);- int actualChar=phraseChars.get(i);
- int resulSum=adds.get(j)+actualChar;
- if(actualChar<=UPPERCASE_UPPERLIMIT&&resulSum>=LOWERCASE_LOWERLIMIT) {
- int offset=resulSum-UPPERCASE_UPPERLIMIT;
- resulSum=LOWERCASE_LOWERLIMIT+offset-1;
- }
- if(resulSum>UPPERCASE_UPPERLIMIT&&resulSum<LOWERCASE_LOWERLIMIT) {
- resulSum+=UPPERTOLOWER_OFFSET;
- }
- else if(resulSum>LOWERCASE_UPPERLIMIT) {
- resulSum=resulSum-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1;
- }
- traduction.add(resulSum);
- j++;
- }
- return traduction.stream()
- .map(n -> (char) n.intValue())
- .map(ch -> Character.toString(ch))
- .collect(Collectors.joining());
- }
- public static String decode(String phrase, String key) {
- return "";
- }
- }
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import java.util.Random; class SolutionTest { @Test void basicTest() { assertEquals("moqik", Kata.encode("abcde", "abcde")); //assertEquals("abcde", Kata.decode("moqik", "abcde")); assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE")); //assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE")); assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH")); //assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH")); assertEquals("ikhwmvi", Kata.encode("deargod", "fgh")); //assertEquals("deargod", Kata.decode("ikhwmvi", "fgh")); assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME")); //assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME")); } @Test void fullTestSimpleOverflow() { assertEquals("CEEpB", Kata.encode("turbo", "TUXON")); //assertEquals("turbo", Kata.decode("CEEpB", "TUXON")); assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh")); //assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh")); assertEquals("IKM", Kata.encode("xyz", "ijklmn")); //assertEquals("xyz", Kata.decode("IKM", "ijklmn")); assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA")); //assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA")); assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID")); //assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID")); } @Test void fullTestIntermediateOverflow() { assertEquals("rhCRDjxXEVyfu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT")); //assertEquals("hOmEsWeEtHoMe", Kata.decode("rhCRDjxXEVyfu", "nOtSoSwEeT")); assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS")); //assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS")); assertEquals("lyynmpA", Kata.encode("Zumbido", "wow")); //assertEquals("Zumbido", Kata.decode("MyynmpA", "wow")); } private String encode(String phrase, String key) { return ""; } private String decode(String phrase, String key) { return ""; } String generateString() { Random random = new Random(); byte[] buffer = new byte[random.nextInt(1501)]; random.nextBytes(buffer); return new String(buffer, java.nio.charset.Charset.forName("UTF-8")); } String generatePhrase() { return generateString(); } String generateKey() { return generateString(); } @RepeatedTest(100) void randomTest() { //String phrase = generatePhrase(); //String key = generateKey(); //assertEquals(Kata.encode(phrase, key), encode(phrase, key)); //assertEquals(Kata.decode(phrase, key), decode(phrase, key)); assertTrue(true); } }
- import static org.junit.jupiter.api.Assertions.*;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import java.util.Random;
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals("moqik", Kata.encode("abcde", "abcde"));
- //assertEquals("abcde", Kata.decode("moqik", "abcde"));
- assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE"));
- //assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE"));
- assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH"));
- //assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH"));
- assertEquals("ikhwmvi", Kata.encode("deargod", "fgh"));
- //assertEquals("deargod", Kata.decode("ikhwmvi", "fgh"));
- assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME"));
- //assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME"));
- }
- @Test
- void fullTestSimpleOverflow() {
- assertEquals("CEEpB", Kata.encode("turbo", "TUXON"));
- //assertEquals("turbo", Kata.decode("CEEpB", "TUXON"));
- assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh"));
- //assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh"));
- assertEquals("IKM", Kata.encode("xyz", "ijklmn"));
- //assertEquals("xyz", Kata.decode("IKM", "ijklmn"));
- assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA"));
- //assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA"));
- assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID"));
- //assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID"));
- }
- @Test
- void fullTestIntermediateOverflow() {
//assertEquals("riDREkxXFVygu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT"));//assertEquals("hOmEsWeEtHoMe", Kata.decode("riDREkxXFVygu", "nOtSoSwEeT"));//assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS"));- assertEquals("rhCRDjxXEVyfu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT"));
- //assertEquals("hOmEsWeEtHoMe", Kata.decode("rhCRDjxXEVyfu", "nOtSoSwEeT"));
- assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS"));
- //assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS"));
//assertEquals("MyynmpA", Kata.encode("Zumbido", "wow"));- assertEquals("lyynmpA", Kata.encode("Zumbido", "wow"));
- //assertEquals("Zumbido", Kata.decode("MyynmpA", "wow"));
- }
- private String encode(String phrase, String key) {
- return "";
- }
- private String decode(String phrase, String key) {
- return "";
- }
- String generateString() {
- Random random = new Random();
- byte[] buffer = new byte[random.nextInt(1501)];
- random.nextBytes(buffer);
- return new String(buffer, java.nio.charset.Charset.forName("UTF-8"));
- }
- String generatePhrase() {
- return generateString();
- }
- String generateKey() {
- return generateString();
- }
- @RepeatedTest(100)
- void randomTest() {
- //String phrase = generatePhrase();
- //String key = generateKey();
- //assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- //assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- assertTrue(true);
- }
- }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
import java.util.List; import java.util.stream.Collectors; public class Kata { private static final int UPPERCASE_LOWERLIMIT = 65; private static final int UPPERCASE_UPPERLIMIT = 90; private static final int LOWERCASE_LOWERLIMIT = 97; private static final int LOWERCASE_UPPERLIMIT = 122; private static final int UPPERTOLOWER_OFFSET = LOWERCASE_LOWERLIMIT-UPPERCASE_UPPERLIMIT-1; private static final int LOWERTOUPPER_OFFSET = LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1; // <<-METHODS->> private static int getLastDigit(int n) { String str = String.valueOf(n); str = str.substring(str.length() - 1, str.length()); return Integer.valueOf(str); } public static String encode(String phrase, String key) { List<Integer> adds = key.chars() .map(n -> getLastDigit(n) + key.length()) .boxed() .toList(); List<Integer> phraseChars = phrase.chars() .boxed() .collect(Collectors.toList()); List<Integer> traduction = new java.util.ArrayList<>(); int j = 0; for (int i = 0; i < phrase.length(); i++) { if (j == adds.size()) j = 0; int resulSum=adds.get(j)+phraseChars.get(i); if(resulSum>UPPERCASE_UPPERLIMIT&&resulSum<LOWERCASE_LOWERLIMIT) { resulSum+=UPPERTOLOWER_OFFSET; } else if(resulSum>LOWERCASE_UPPERLIMIT) { resulSum=resulSum-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1; } traduction.add(resulSum); j++; } return traduction.stream() .map(n -> (char) n.intValue()) .map(ch -> Character.toString(ch)) .collect(Collectors.joining()); } public static String decode(String phrase, String key) { return ""; } }
- import java.util.List;
- import java.util.stream.Collectors;
- public class Kata {
- private static final int UPPERCASE_LOWERLIMIT = 65;
- private static final int UPPERCASE_UPPERLIMIT = 90;
- private static final int LOWERCASE_LOWERLIMIT = 97;
- private static final int LOWERCASE_UPPERLIMIT = 122;
- private static final int UPPERTOLOWER_OFFSET = LOWERCASE_LOWERLIMIT-UPPERCASE_UPPERLIMIT-1;
- private static final int LOWERTOUPPER_OFFSET = LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1;
- // <<-METHODS->>
- private static int getLastDigit(int n) {
- String str = String.valueOf(n);
- str = str.substring(str.length() - 1, str.length());
- return Integer.valueOf(str);
- }
- public static String encode(String phrase, String key) {
- List<Integer> adds = key.chars()
- .map(n -> getLastDigit(n) + key.length())
- .boxed()
- .toList();
- List<Integer> phraseChars = phrase.chars()
- .boxed()
- .collect(Collectors.toList());
- List<Integer> traduction = new java.util.ArrayList<>();
- int j = 0;
- for (int i = 0; i < phrase.length(); i++) {
- if (j == adds.size()) j = 0;
traduction.add(adds.get(j) + phraseChars.get(i));- int resulSum=adds.get(j)+phraseChars.get(i);
- if(resulSum>UPPERCASE_UPPERLIMIT&&resulSum<LOWERCASE_LOWERLIMIT) {
- resulSum+=UPPERTOLOWER_OFFSET;
- }
- else if(resulSum>LOWERCASE_UPPERLIMIT) {
- resulSum=resulSum-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-1;
- }
- traduction.add(resulSum);
- j++;
- }
- return traduction.stream()
- .map(n -> (char) n.intValue())
- .map(ch -> Character.toString(ch))
- .collect(Collectors.joining());
- }
- public static String decode(String phrase, String key) {
- return "";
- }
- }
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import java.util.Random; class SolutionTest { @Test void basicTest() { assertEquals("moqik", Kata.encode("abcde", "abcde")); //assertEquals("abcde", Kata.decode("moqik", "abcde")); assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE")); //assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE")); assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH")); //assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH")); assertEquals("ikhwmvi", Kata.encode("deargod", "fgh")); //assertEquals("deargod", Kata.decode("ikhwmvi", "fgh")); assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME")); //assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME")); } @Test void fullTestSimpleOverflow() { assertEquals("CEEpB", Kata.encode("turbo", "TUXON")); //assertEquals("turbo", Kata.decode("CEEpB", "TUXON")); assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh")); //assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh")); assertEquals("IKM", Kata.encode("xyz", "ijklmn")); //assertEquals("xyz", Kata.decode("IKM", "ijklmn")); assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA")); //assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA")); assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID")); //assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID")); } @Test void fullTestIntermediateOverflow() { //assertEquals("riDREkxXFVygu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT")); //assertEquals("hOmEsWeEtHoMe", Kata.decode("riDREkxXFVygu", "nOtSoSwEeT")); //assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS")); //assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS")); //assertEquals("MyynmpA", Kata.encode("Zumbido", "wow")); //assertEquals("Zumbido", Kata.decode("MyynmpA", "wow")); } private String encode(String phrase, String key) { return ""; } private String decode(String phrase, String key) { return ""; } String generateString() { Random random = new Random(); byte[] buffer = new byte[random.nextInt(1501)]; random.nextBytes(buffer); return new String(buffer, java.nio.charset.Charset.forName("UTF-8")); } String generatePhrase() { return generateString(); } String generateKey() { return generateString(); } @RepeatedTest(100) void randomTest() { //String phrase = generatePhrase(); //String key = generateKey(); //assertEquals(Kata.encode(phrase, key), encode(phrase, key)); //assertEquals(Kata.decode(phrase, key), decode(phrase, key)); assertTrue(true); } }
- import static org.junit.jupiter.api.Assertions.*;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import java.util.Random;
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals("moqik", Kata.encode("abcde", "abcde"));
- //assertEquals("abcde", Kata.decode("moqik", "abcde"));
- assertEquals("KMOQS", Kata.encode("ABCDE", "ABCDE"));
- //assertEquals("ABCDE", Kata.decode("KMOQS", "ABCDE"));
- assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH"));
- //assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH"));
- assertEquals("ikhwmvi", Kata.encode("deargod", "fgh"));
- //assertEquals("deargod", Kata.decode("ikhwmvi", "fgh"));
- assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME"));
- //assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME"));
- }
- @Test
void fullTest() {assertEquals("CDEfA", Kata.encode("turbo", "TUXON"));assertEquals("turbo", Kata.decode("CDEfA", "TUXON"));assertEquals("skstzDvzwj", Kata.encode("helloworld", "afgh"));assertEquals("helloworld", Kata.decode("skstzDvzwj", "afgh"));assertEquals("JLN", Kata.encode("xyz", "ijklmn"));assertEquals("xyz", Kata.decode("JLN", "ijklmn"));assertEquals("riDREkxXFVygu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT"));assertEquals("hOmEsWeEtHoMe", Kata.decode("riDREkxXFVygu", "nOtSoSwEeT"));- void fullTestSimpleOverflow() {
- assertEquals("CEEpB", Kata.encode("turbo", "TUXON"));
- //assertEquals("turbo", Kata.decode("CEEpB", "TUXON"));
- assertEquals("skstzCvzwj", Kata.encode("helloworld", "afgh"));
- //assertEquals("helloworld", Kata.decode("skstzCvzwj", "afgh"));
- assertEquals("IKM", Kata.encode("xyz", "ijklmn"));
- //assertEquals("xyz", Kata.decode("IKM", "ijklmn"));
- assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA"));
assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA"));assertEquals("byvNMwgiVt", Kata.encode("WonDErWaLl", "oASiS"));assertEquals("WonDErWaLl", Kata.decode("byvNMwgiVt", "oASiS"));assertEquals("MyynmpA", Kata.encode("Zumbido", "wow"));assertEquals("Zumbido", Kata.decode("MyynmpA", "wow"));- //assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA"));
assertEquals("BOywAJdrzSfbLMCuCnViNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID"));assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywAJdrzSfbLMCuCnViNt", "dAvID"));- assertEquals("BOywIJdrzafbLMKuCnVqNt", Kata.encode("wElovETerNaRyExpsaNdIj", "dAvID"));
- //assertEquals("wElovETerNaRyExpsaNdIj", Kata.decode("BOywIJdrzafbLMKuCnVqNt", "dAvID"));
- }
- @Test
- void fullTestIntermediateOverflow() {
- //assertEquals("riDREkxXFVygu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT"));
- //assertEquals("hOmEsWeEtHoMe", Kata.decode("riDREkxXFVygu", "nOtSoSwEeT"));
- //assertEquals("cyvNMxgiVt", Kata.encode("WonDErWaLl", "oASiS"));
- //assertEquals("WonDErWaLl", Kata.decode("cyvNMxgiVt", "oASiS"));
- //assertEquals("MyynmpA", Kata.encode("Zumbido", "wow"));
- //assertEquals("Zumbido", Kata.decode("MyynmpA", "wow"));
- }
- private String encode(String phrase, String key) {
- return "";
- }
- private String decode(String phrase, String key) {
- return "";
- }
- String generateString() {
- Random random = new Random();
- byte[] buffer = new byte[random.nextInt(1501)];
- random.nextBytes(buffer);
- return new String(buffer, java.nio.charset.Charset.forName("UTF-8"));
- }
- String generatePhrase() {
- return generateString();
- }
- String generateKey() {
- return generateString();
- }
- @RepeatedTest(100)
- void randomTest() {
- //String phrase = generatePhrase();
- //String key = generateKey();
- //assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- //assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- assertTrue(true);
- }
- }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import java.util.Random; class SolutionTest { @Test void basicTest() { assertEquals("moqik", Kata.encode("abcde", "abcde")); assertEquals("abcde", Kata.decode("moqik", "abcde")); assertEquals("KMOUS", Kata.encode("ABCDE", "ABCDE")); assertEquals("ABCDE", Kata.decode("KMOUS", "ABCDE")); assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH")); assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH")); assertEquals("ikhwmvi", Kata.encode("deargod", "fgh")); assertEquals("deargod", Kata.decode("ikhwmvi", "fgh")); assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME")); assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME")); } @Test void fullTest() { assertEquals("CDEfA", Kata.encode("turbo", "TUXON")); assertEquals("turbo", Kata.decode("CDEfA", "TUXON")); assertEquals("skstzDvzwj", Kata.encode("helloworld", "afgh")); assertEquals("helloworld", Kata.decode("skstzDvzwj", "afgh")); assertEquals("JLN", Kata.encode("xyz", "ijklmn")); assertEquals("xyz", Kata.decode("JLN", "ijklmn")); assertEquals("riDREkxXFVygu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT")); assertEquals("hOmEsWeEtHoMe", Kata.decode("riDREkxXFVygu", "nOtSoSwEeT")); assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA")); assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA")); assertEquals("byvNMwgiVt", Kata.encode("WonDErWaLl", "oASiS")); assertEquals("WonDErWaLl", Kata.decode("byvNMwgiVt", "oASiS")); } private String encode(String phrase, String key) { return ""; } private String decode(String phrase, String key) { return ""; } String generateString() { Random random = new Random(); byte[] buffer = new byte[random.nextInt(1501)]; random.nextBytes(buffer); return new String(buffer, java.nio.charset.Charset.forName("UTF-8")); } String generatePhrase() { return generateString(); } String generateKey() { return generateString(); } @RepeatedTest(100) void randomTest() { String phrase = generatePhrase(); String key = generateKey(); assertEquals(Kata.encode(phrase, key), encode(phrase, key)); assertEquals(Kata.decode(phrase, key), decode(phrase, key)); } }
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import java.util.Random;
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals("moqik", Kata.encode("abcde", "abcde"));
- assertEquals("abcde", Kata.decode("moqik", "abcde"));
- assertEquals("KMOUS", Kata.encode("ABCDE", "ABCDE"));
- assertEquals("ABCDE", Kata.decode("KMOUS", "ABCDE"));
- assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH"));
- assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH"));
- assertEquals("ikhwmvi", Kata.encode("deargod", "fgh"));
- assertEquals("deargod", Kata.decode("ikhwmvi", "fgh"));
- assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME"));
- assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME"));
- }
- @Test
- void fullTest() {
- assertEquals("CDEfA", Kata.encode("turbo", "TUXON"));
- assertEquals("turbo", Kata.decode("CDEfA", "TUXON"));
- assertEquals("skstzDvzwj", Kata.encode("helloworld", "afgh"));
- assertEquals("helloworld", Kata.decode("skstzDvzwj", "afgh"));
- assertEquals("JLN", Kata.encode("xyz", "ijklmn"));
- assertEquals("xyz", Kata.decode("JLN", "ijklmn"));
- assertEquals("riDREkxXFVygu", Kata.encode("hOmEsWeEtHoMe", "nOtSoSwEeT"));
- assertEquals("hOmEsWeEtHoMe", Kata.decode("riDREkxXFVygu", "nOtSoSwEeT"));
- assertEquals("qUlWuZXovQ", Kata.encode("gOdMoRNinG", "uSA"));
- assertEquals("gOdMoRNinG", Kata.decode("qUlWuZXovQ", "uSA"));
- assertEquals("byvNMwgiVt", Kata.encode("WonDErWaLl", "oASiS"));
- assertEquals("WonDErWaLl", Kata.decode("byvNMwgiVt", "oASiS"));
- }
- private String encode(String phrase, String key) {
- return "";
- }
- private String decode(String phrase, String key) {
- return "";
- }
- String generateString() {
- Random random = new Random();
- byte[] buffer = new byte[random.nextInt(1501)];
- random.nextBytes(buffer);
- return new String(buffer, java.nio.charset.Charset.forName("UTF-8"));
- }
- String generatePhrase() {
- return generateString();
- }
- String generateKey() {
- return generateString();
- }
- @RepeatedTest(100)
- void randomTest() {
- String phrase = generatePhrase();
- String key = generateKey();
- assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- }
- }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import java.util.Random; import java.nio.charset.Charset; class SolutionTest { @Test void basicTest() { assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH")); assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH")); assertEquals("ikhwmvi", Kata.encode("deargod", "fgh")); assertEquals("deargod", Kata.decode("ikhwmvi", "fgh")); assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME")); assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME")); } @Test void fullTest() { assertEquals("skstzDvzwj", Kata.encode("helloworld", "afgh")); assertEquals("helloworld", Kata.decode("skstzDvzwj", "afgh")); } private String encode(String phrase, String key) { return ""; } private String decode(String phrase, String key) { return ""; } String generateString() { Random random = new Random(); byte[] buffer = new byte[random.nextInt(1501)]; random.nextBytes(buffer); return new String(buffer, Charset.forName("UTF-8")); } String generatePhrase() { return generateString(); } String generateKey() { return generateString(); } @RepeatedTest(100) void randomTest() { String phrase = generatePhrase(); String key = generateKey(); assertEquals(Kata.encode(phrase, key), encode(phrase, key)); assertEquals(Kata.decode(phrase, key), decode(phrase, key)); } }
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import java.util.Random;
- import java.nio.charset.Charset;
- class SolutionTest {
- @Test
- void basicTest() {
assertEquals("S", Kata.encode("DEARGOD", "afgh"));assertEquals("DEARGOD", Kata.decode("", "afgh"));assertEquals("", Kata.encode("", ""));assertEquals("", Kata.decode("", ""));- assertEquals("GIFUKTG", Kata.encode("DEARGOD", "FGH"));
- assertEquals("DEARGOD", Kata.decode("GIFUKTG", "FGH"));
- assertEquals("ikhwmvi", Kata.encode("deargod", "fgh"));
- assertEquals("deargod", Kata.decode("ikhwmvi", "fgh"));
- assertEquals("IQlOirL", Kata.encode("ALaBamA", "hoME"));
- assertEquals("ALaBamA", Kata.decode("IQlOirL", "hoME"));
- }
- @Test
- void fullTest() {
- assertEquals("skstzDvzwj", Kata.encode("helloworld", "afgh"));
- assertEquals("helloworld", Kata.decode("skstzDvzwj", "afgh"));
- }
- private String encode(String phrase, String key) {
- return "";
- }
- private String decode(String phrase, String key) {
- return "";
- }
- String generateString() {
- Random random = new Random();
- byte[] buffer = new byte[random.nextInt(1501)];
- random.nextBytes(buffer);
- return new String(buffer, Charset.forName("UTF-8"));
- }
- String generatePhrase() {
- return generateString();
- }
- String generateKey() {
- return generateString();
- }
- @RepeatedTest(100)
- void randomTest() {
- String phrase = generatePhrase();
- String key = generateKey();
- assertEquals(Kata.encode(phrase, key), encode(phrase, key));
- assertEquals(Kata.decode(phrase, key), decode(phrase, key));
- }
- }