Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner keyboard = new Scanner(System.in); //DAD'S CODE
- String userText;
- int shift = 0;
- String newText = null;
- userText = keyboard.nextLine();
- shift = keyboard.nextInt();
- int userTextnum = userText.length();
- System.out.println(userTextnum);
- String encrypted = null;
- String decrypted = null;
- char [] userTextChars = userText.toCharArray();
- char [] userTextChars2 = userText.toCharArray();
- if (userText != null) {
- for (int k = 0; ; k++) {
- char userChar = userText.charAt(k);
- System.out.println(userChar);
- int usernum = (int) userChar;
- System.out.println(usernum);
- int rem = (usernum + shift) % 126;
- System.out.println(rem);
- userTextChars[k] = (char) rem;
- userText = String.valueOf(userTextChars);
- encrypted = userText;
- if (k == userTextnum -1 ) {
- for (int l = 0; ; l++) {
- char userChar2 = userText.charAt(l);
- int usernum2 = (int) userChar2;
- System.out.println(userChar2);
- System.out.println(usernum2 - shift);
- usernum2 = ((((usernum2 - shift) % 126) * 126) / 126) - shift;
- userTextChars[l] = (char) usernum2;
- userText = String.valueOf(userTextChars);
- decrypted = userText;
- if (l == userTextnum - 1) {
- break;
- }
- }
- break;
- }
- }
- }
- System.out.println(encrypted);
- System.out.println(decrypted);
- _______________________________________________________________________________________________________________________________________
- Scanner keyboard = new Scanner(System.in); //MY CODE
- char [] cipher = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
- String userText;
- int shift = 0;
- userText = keyboard.nextLine();
- shift = keyboard.nextInt();
- char [] userTextChars = userText.toCharArray();
- if (userText != null) {
- for (int i = 0; i <= 25; i++) {
- if (i == userText.length()) {
- break;
- } else {
- for (int k = 0; ; k++) {
- char userChar = userText.charAt(i);
- if (userChar == cipher[k]) {
- int recycle = (k + shift) % cipher.length;
- userTextChars[i] = cipher[recycle];
- userText = String.valueOf(userTextChars);
- break;
- }
- }
- }
- }
- System.out.println(userText);
- }
- _______________________________________________________________________________________________________________________________________
- Scanner keyboard = new Scanner(System.in); #NEW CODE I WILL USE (SIMPLIFIED)
- String [] alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
- String wordToNum;
- String numToWord;
- String encrypt = null;
- String decrypt = null;
- wordToNum = keyboard.nextLine();
- numToWord = keyboard.nextLine();
- if (wordToNum != null) {
- for (int i = 0; i <= 25; i++){
- String loopNum = Integer.toString(i);
- wordToNum = wordToNum.replaceAll(alphabet[i], loopNum);
- }
- }
- if (numToWord != null) {
- for (int l = 0; l <= 25; l++){
- String loopNum2 = Integer.toString(l);
- numToWord = numToWord.replaceAll(loopNum2, alphabet[l]);
- }
- }
- System.out.println(wordToNum);
- System.out.println(numToWord);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement