Created
January 28, 2019 15:06
-
-
Save memish/f4bf5b3e88a710161e35ea2558a92737 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Cryptogram | |
{ | |
public static void main (String[] args) | |
{ | |
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray(); | |
String[] al=new String[26];//you can use this array for finding the location of character in the alphabet | |
for(int i=0; i < alphabet.length; i++){// this sets each letter of alphabet into string array al[] | |
al[i]=String.valueOf(alphabet[i]); | |
} | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter Text to be encrypted (letters only)"); | |
String quote= sc.nextLine(); | |
char[] quoteArray = quote.toCharArray(); | |
String[] QA =new String[quoteArray.length];//strings are easier to compare | |
for(int i=0; i < quoteArray.length; i++){// Sets each letter of the entered text to QA array | |
QA[i]=String.valueOf(quoteArray[i]); | |
} | |
//START HERE: You don't really need to look at code above | |
//keys to remember: the array al[] holds all 26 letters of alphabet | |
//the QA[] array holds each character of the text the user entered | |
//use the for loops below to examine each character of the QA array and see where it exist | |
//in the al[] array. then shift according to the shift value and save to the encryptedQuote arraylist | |
ArrayList encryptedQuote = new ArrayList();//save each encrypted character to ArrayList | |
int shift = 5;//use this as your shift | |
/* | |
* 1) examine each charactor of the QA[] array and shift the character by the shift variable amount | |
* (use modulus to wrap character around) | |
* 2) save each encrypted character to ArrayList - | |
* 3) 3 variables you'll use are al[] array, QA[] array and encryptedQuote arraylist | |
* 4) display encrypted text to screen by reading through the arraylist | |
* you can test that your encryption worked by using website below | |
* https://learncryptography.com/classical-encryption/caesar-cipher | |
*/ | |
for(int i=0; i < QA.length; i++){//look through QA array | |
for(int j=0; j < al.length; j++){ | |
} | |
} | |
//lastly, create a for loop g here and display the characters in the encryptedQuote arraylist | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment