Ad
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • import java.util.List;
    import java.util.stream.Collectors;
    
    public class Kata {
      
      // <<-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> traduction) {
    		return traduction.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 java.util.List;
    • import java.util.stream.Collectors;
    • public class Kata {
    • // <<-CONSTANTS->>
    • // <<-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()
    • private static String parseChars(List<Integer> traduction) {
    • return traduction.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() || key == null) return "";
    • if (key.isEmpty()) return phrase;
    • 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> translation = new java.util.ArrayList<>();
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 0;
    • for (int i = 0; i < phrase.length(); i++) {
    • keyIndex = i % offsets.size();
    • 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;
    • }
    • translation.add(result);
    • keyIndex++;
    • traduction.add(result);
    • }
    • return parseChars(translation);
    • return parseChars(traduction);
    • }
    • public static String decode(String phrase, String key) {
    • if (phrase == null || phrase.isEmpty() || key == null) return "";
    • if (key.isEmpty()) return phrase;
    • 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> translation = new java.util.ArrayList<>();
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 0;
    • for (int i = 0; i < phrase.length(); i++) {
    • keyIndex = i % offsets.size();
    • 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;
    • }
    • translation.add(result);
    • keyIndex++;
    • traduction.add(result);
    • }
    • return parseChars(translation);
    • return parseChars(traduction);
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • import java.util.List;
    import java.util.stream.Collectors;
    
    public class Kata {
    	
    	// <<-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> traduction) {
    		return traduction.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() || key == null) return "";
    		if (key.isEmpty()) return phrase;
        
    		List<Integer> offsets     = getEncryptationOffsets(key);
    		List<Integer> phraseChars = getPhraseChars(phrase);
    		List<Integer> traduction  = new java.util.ArrayList<>();
    
    		int keyIndex = 0;
    		for (int i = 0; i < phrase.length(); i++) {
    			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);
    			keyIndex++;
    		}
    
    		return parseChars(traduction);
    	}
    
    	public static String decode(String phrase, String key) {
    		if (phrase == null || phrase.isEmpty() || key == null) return "";
    		if (key.isEmpty()) return phrase;
        
    		List<Integer> offsets     = getEncryptationOffsets(key);
    		List<Integer> phraseChars = getPhraseChars(phrase);
    		List<Integer> traduction  = new java.util.ArrayList<>();
    
    		int keyIndex = 0;
    		for (int i = 0; i < phrase.length(); i++) {
    			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);
    			keyIndex++;
    		}
    
    		return parseChars(traduction);
    	}
      
    }
    • import java.util.List;
    • import java.util.stream.Collectors;
    • public class Kata {
    • // <<-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> traduction) {
    • return traduction.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() || key == null) return "";
    • if (key.isEmpty()) return phrase;
    • List<Integer> offsets = getEncryptationOffsets(key);
    • List<Integer> phraseChars = getPhraseChars(phrase);
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 0;
    • for (int i = 0; i < phrase.length(); i++) {
    • if (keyIndex == offsets.size())
    • keyIndex = 0;
    • 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);
    • keyIndex++;
    • }
    • return parseChars(traduction);
    • }
    • public static String decode(String phrase, String key) {
    • if (phrase == null || phrase.isEmpty() || key == null) return "";
    • if (key.isEmpty()) return phrase;
    • List<Integer> offsets = getEncryptationOffsets(key);
    • List<Integer> phraseChars = getPhraseChars(phrase);
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 0;
    • for (int i = 0; i < phrase.length(); i++) {
    • if (keyIndex == offsets.size())
    • keyIndex = 0;
    • 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);
    • keyIndex++;
    • }
    • return parseChars(traduction);
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • import java.util.List;
    import java.util.stream.Collectors;
    
    public class Kata {
    	
    	// <<-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> traduction) {
    		return traduction.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() || key == null) return "";
    		if (key.isEmpty()) return phrase;
        
    		List<Integer> offsets     = getEncryptationOffsets(key);
    		List<Integer> phraseChars = getPhraseChars(phrase);
    		List<Integer> traduction  = new java.util.ArrayList<>();
    
    		int keyIndex = 0;
    		for (int i = 0; i < phrase.length(); i++) {
    			if (keyIndex == offsets.size())
    				keyIndex = 0;
    			
    			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);
    			keyIndex++;
    		}
    
    		return parseChars(traduction);
    	}
    
    	public static String decode(String phrase, String key) {
    		if (phrase == null || phrase.isEmpty() || key == null) return "";
    		if (key.isEmpty()) return phrase;
        
    		List<Integer> offsets     = getEncryptationOffsets(key);
    		List<Integer> phraseChars = getPhraseChars(phrase);
    		List<Integer> traduction  = new java.util.ArrayList<>();
    
    		int keyIndex = 0;
    		for (int i = 0; i < phrase.length(); i++) {
    			if (keyIndex == offsets.size())
    				keyIndex = 0;
    			
    			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);
    			keyIndex++;
    		}
    
    		return parseChars(traduction);
    	}
      
    }
    • import java.util.List;
    • import java.util.stream.Collectors;
    • public class Kata {
    • // <<-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> traduction) {
    • return traduction.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() || key == null) return "";
    • if (key.isEmpty()) return phrase;
    • List<Integer> offsets = getEncryptationOffsets(key);
    • List<Integer> phraseChars = getPhraseChars(phrase);
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 0;
    • for (int i = 0; i < phrase.length(); i++) {
    • if (keyIndex == offsets.size())
    • keyIndex = 0;
    • 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);
    • keyIndex++;
    • }
    • return parseChars(traduction);
    • }
    • public static String decode(String phrase, String key) {
    • if (phrase == null || phrase.isEmpty() || key == null) return "";
    • if (key.isEmpty()) return phrase;
    • List<Integer> offsets = getEncryptationOffsets(key);
    • List<Integer> phraseChars = getPhraseChars(phrase);
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 0;
    • for (int i = 0; i < phrase.length(); i++) {
    • if (keyIndex == offsets.size())
    • keyIndex = 0;
    • 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);
    • keyIndex++;
    • }
    • return parseChars(traduction);
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • import java.util.List;
    import java.util.stream.Collectors;
    
    public class Kata {
    	
    	// <<-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> traduction) {
    		return traduction.stream()
    				.map(n -> (char) n.intValue())
    				.map(c -> Character.toString(c))
    				.collect(Collectors.joining());
    	}
    
    	public static String encode(String phrase, String key) {
    		List<Integer> offsets     = getEncryptationOffsets(key);
    		List<Integer> phraseChars = getPhraseChars(phrase);
    		List<Integer> traduction  = new java.util.ArrayList<>();
    
    		int keyIndex = 0;
    		for (int i = 0; i < phrase.length(); i++) {
    			if (keyIndex == offsets.size())
    				keyIndex = 0;
    			
    			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);
    			keyIndex++;
    		}
    
    		return parseChars(traduction);
    	}
    
    	public static String decode(String phrase, String key) {
    		List<Integer> offsets     = getEncryptationOffsets(key);
    		List<Integer> phraseChars = getPhraseChars(phrase);
    		List<Integer> traduction  = new java.util.ArrayList<>();
    
    		int keyIndex = 0;
    		for (int i = 0; i < phrase.length(); i++) {
    			if (keyIndex == offsets.size())
    				keyIndex = 0;
    			
    			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);
    			keyIndex++;
    		}
    
    		return parseChars(traduction);
    	}
      
    }
    • 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());
    • // <<-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);
    • }
    • 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()
    • 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());
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int j = 0;
    • }
    • private static String parseChars(List<Integer> traduction) {
    • return traduction.stream()
    • .map(n -> (char) n.intValue())
    • .map(c -> Character.toString(c))
    • .collect(Collectors.joining());
    • }
    • public static String encode(String phrase, String key) {
    • List<Integer> offsets = getEncryptationOffsets(key);
    • List<Integer> phraseChars = getPhraseChars(phrase);
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 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;
    • if (keyIndex == offsets.size())
    • keyIndex = 0;
    • 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;
    • }
    • else if(result>LOWERCASE_UPPERLIMIT) {
    • result=result-LOWERCASE_UPPERLIMIT+UPPERCASE_LOWERLIMIT-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);
    • j++;
    • keyIndex++;
    • }
    • return traduction.stream()
    • .map(n -> (char) n.intValue())
    • .map(ch -> Character.toString(ch))
    • .collect(Collectors.joining());
    • return parseChars(traduction);
    • }
    • /*-----------------------------------------------------------------------------------*/
    • 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());
    • public static String decode(String phrase, String key) {
    • List<Integer> offsets = getEncryptationOffsets(key);
    • List<Integer> phraseChars = getPhraseChars(phrase);
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int keyIndex = 0;
    • for (int i = 0; i < phrase.length(); i++) {
    • if (keyIndex == offsets.size())
    • keyIndex = 0;
    • 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++;
    • 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);
    • keyIndex++;
    • }
    • return traduction.stream()
    • .map(n -> (char) n.intValue())
    • .map(ch -> Character.toString(ch))
    • .collect(Collectors.joining());
    • }
    • return parseChars(traduction);
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • import java.util.List;
    import java.util.stream.Collectors;
    
    public class Kata {
    	
      // <<-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));
    			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 {
    • // <<-METHODS->>
    • private static int getLastDigit(int n) {
    • String str = String.valueOf(n);
    • str = str.substring(str.length() - 1, str.length());
    • return Integer.valueOf(str);
    • }
    • private static String encode(String phrase, String key) {
    • public static String encode(String phrase, String key) {
    • List<Integer> adds = key.chars()
    • .map(n -> getLastDigit(n) + key.length())
    • .boxed()
    • .toList();
    • StringBuilder sb = new StringBuilder();
    • List<Integer> pAscii = phrase.chars()
    • List<Integer> phraseChars = phrase.chars()
    • .boxed()
    • .collect(Collectors.toList());
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int counter;
    • for (int i = 0; i < phrase.length(); i += key.length()) {
    • counter = 0;
    • for (int j = i; j < key.length() + i; j++) {
    • traduction.add(pAscii.get(j) + adds.get(counter));
    • counter++;
    • }
    • 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));
    • j++;
    • }
    • return traduction.stream()
    • .map(Integer::intValue)
    • .map(Character::getName)
    • .map(n -> (char) n.intValue())
    • .map(ch -> Character.toString(ch))
    • .collect(Collectors.joining());
    • }
    • public static String decode(String phrase, String key) {
    • return "";
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • public class Kata {
    	
      // <<-METHODS->>
    	private static int getLastDigit(int n) {
    		String str = String.valueOf(n);
    		str = str.substring(str.length() - 1, str.length());
    		return Integer.valueOf(str);
    	}
    	
    	private static String encode(String phrase, String key) {
    		List<Integer> adds = key.chars()
    			.map(n -> getLastDigit(n) + key.length())
    			.boxed()
    			.toList(); 
    		
    		StringBuilder sb = new StringBuilder();
    		
    		List<Integer> pAscii = phrase.chars()
    				.boxed()
    				.collect(Collectors.toList());
    		
    		List<Integer> traduction = new java.util.ArrayList<>();
    		int counter;
    		for (int i = 0; i < phrase.length(); i += key.length()) {
    			counter = 0;
    			for (int j = i; j < key.length() + i; j++) {
    				traduction.add(pAscii.get(j) + adds.get(counter));
    				counter++;
    			}
    		}
    		
    		return traduction.stream()
    				.map(Integer::intValue)
    				.map(Character::getName)
    				.collect(Collectors.joining());
    	}
      
      public static String decode(String phrase, String key) {
        return "";
      }
      
    }
    • public class Kata {
    • public static String encode(String phrase, String key) {
    • return "";
    • }
    • // <<-METHODS->>
    • private static int getLastDigit(int n) {
    • String str = String.valueOf(n);
    • str = str.substring(str.length() - 1, str.length());
    • return Integer.valueOf(str);
    • }
    • private static String encode(String phrase, String key) {
    • List<Integer> adds = key.chars()
    • .map(n -> getLastDigit(n) + key.length())
    • .boxed()
    • .toList();
    • StringBuilder sb = new StringBuilder();
    • List<Integer> pAscii = phrase.chars()
    • .boxed()
    • .collect(Collectors.toList());
    • List<Integer> traduction = new java.util.ArrayList<>();
    • int counter;
    • for (int i = 0; i < phrase.length(); i += key.length()) {
    • counter = 0;
    • for (int j = i; j < key.length() + i; j++) {
    • traduction.add(pAscii.get(j) + adds.get(counter));
    • counter++;
    • }
    • }
    • return traduction.stream()
    • .map(Integer::intValue)
    • .map(Character::getName)
    • .collect(Collectors.joining());
    • }
    • public static String decode(String phrase, String key) {
    • return "";
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
public class Kata {
  
  public static String encode(String phrase, String key) {
    return "";
  }
  
  public static String decode(String phrase, String key) {
    return "";
  }
  
}