Ad
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • 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());
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • 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 "";
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Code
Diff
  • 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 "";
    • }
    • }
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
Strings
Ciphers
Fundamentals
Cryptography
Algorithms