Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Shift numbers into new places based on the key
- public static int[] arrayShift(int shiftKey, int[]numSent)
- {
- int x = 0;
- //Shift array
- for(int number1 : numSent) //shiftKey is the amount the number is shifted
- {
- number1 += shiftKey;
- }
- //Loop array around ASCII alphabet
- for(int number2 : numSent)
- {
- //If
- if(number2 > 122) //x is the variable that tells how much it should be shifted after looping back around from z to a
- {
- x = (number2 - 122);
- number2 = (96 + x);
- }
- }
- //array of numbers representing ASCII values in int form
- return numSent;
- }
- //Turn number array (ASCII values in int form) into character array (ASCII values in char form)
- public static char[] charShift(int[]numSent, int sentLength)
- {
- char[]charSent = new char[sentLength]; //Makes an array preparing to contain the characters
- int b = 0;
- for(int number3 : numSent)
- {
- charSent[b] = (char)number3; //Turns the int values into char values
- b++;
- }
- //array of chars in ASCII value form
- return charSent;
- }
- public static String shift(int shiftKey, String trueSentence)
- {
- String trueSent = trueSentence.trim();
- int trueSentLength = trueSent.length();
- char[] trueSentSplit = trueSent.toCharArray();
- int[]shiftSent = new int[trueSentLength]; //Creates an array preparing to hold integer values representing ASCII
- int a = 0;
- for(char sentPiece : trueSentSplit)
- {
- shiftSent[a] = sentPiece; //Turns each value in the character array into an integer array representing ASCII values
- a++;
- }
- //Shift numbers
- int numList[] = arrayShift(shiftKey, shiftSent);
- //Turn number array into character array
- char charList[] = charShift(numList, trueSentLength);
- //Turn character array into new, translated String
- String falseSent = new String(charList);
- //new, encrypted sentence
- return falseSent;
- }
- //Runs shift()
- public static String getFalseSent(int shiftKey1, String trueSentence1)
- {
- String falseSent = shift(shiftKey1, trueSentence1);
- return falseSent;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement