<file_sep>package coursera;

public class NewCeaserCipher {
	/*public static String encrypt(String input, int key)
	{
		String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String shiftAlphabets = alphabet.substring(key) + alphabet.substring(0,  key);
		StringBuilder newStringB = new StringBuilder(input); 
		for(int i =0; i<newStringB.length(); i++)
		{
			char eachCharacter = newStringB.charAt(i);
			char upperEachCharacter = Character.toUpperCase(eachCharacter);
			int index = alphabet.indexOf(upperEachCharacter);
			if(index != -1)
			{
				char newChar = shiftAlphabets.charAt(index);
				if(Character.isLowerCase(eachCharacter))
				{
					newChar = Character.toLowerCase(newChar);
				}
				newStringB.setCharAt(i, newChar);
			}
		}
		return newStringB.toString();
	}*/
	
	public static String encryptTwoWays(String input, int key1, int key2 )
	{
		String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String shiftAlphabets1 = alphabet.substring(key1) + alphabet.substring(0,  key1);
		String shiftAlphabets2 = alphabet.substring(key2) + alphabet.substring(0,  key2);
		StringBuilder newStringB = new StringBuilder(input); 
		for(int i =0; i<newStringB.length(); i++)
		{
			char eachCharacter = newStringB.charAt(i);
			char upperEachCharacter = Character.toUpperCase(eachCharacter);
			int index = alphabet.indexOf(upperEachCharacter);
			char newChar;			if(index != -1)
			{
				if(i%2 == 0)
				{
					newChar = shiftAlphabets1.charAt(index);
				}
				else {
					newChar = shiftAlphabets2.charAt(index);
				}
				if(Character.isLowerCase(eachCharacter))
				{
					newChar = Character.toLowerCase(newChar);
				}
				newStringB.setCharAt(i, newChar);
			}
		}
		return newStringB.toString();
	}
	
	public static void main(String[] args)
	{
		String newString = "Top ncmy qkff vi vguv vbg ycpx";
		int key1 = 2, key2 = 20;
		System.out.println(encryptTwoWays(newString, key1, key2));
	}
}
<file_sep>package coursera;

public class WordPlay {
	public static boolean isVowel(char ch)
	{
		char UpperCasech = Character.toUpperCase(ch);
		if (UpperCasech == 'A' || UpperCasech == 'E'||UpperCasech == 'I'||UpperCasech == 'O'||UpperCasech == 'U')
		{
			return true;
		}
		else {
			return false;
		}
	}
	
	public static String replace(String phrase, char ch)
	{
		StringBuilder newString = new StringBuilder(phrase);
		for(int i=0; i<newString.length(); i++)
		{
			char phraseChar = newString.charAt(i);
			if(isVowel(phraseChar))
			{
				newString.setCharAt(i,ch);
			}
		}
		return newString.toString();
		
	}
	
	public static String emphasize(String phrase, char ch)
	{
		StringBuilder newStringBuilder = new StringBuilder(phrase);
		for(int i =0; i<newStringBuilder.length(); i++)
		{
			char eachCharacter = newStringBuilder.charAt(i);
			int index = i + 1;
			if(Character.toLowerCase(eachCharacter) == ch)
			{
				if(index%2 == 0)
				{
					newStringBuilder.setCharAt(i, '+');
				}
				else {
					newStringBuilder.setCharAt(i, '*');
				}
			}
		}
		return newStringBuilder.toString();
	}
	
	public static void main(String[] args)
	{
		String newString = "<NAME>";
		System.out.println(replace(newString, '*'));
		System.out.println(emphasize(newString, 'a'));
	}
}
<file_sep>package coursera;

public class DecryptCeaserCipher {
	public static int[] countElements(String str)
	{
		int[] counter = new int[26];
		//Writing down the alphabets
		String alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for(int i=0; i<str.length(); i++)
		{
			char currChar = str.charAt(i);
			char upperCurrChar = Character.toUpperCase(currChar);
			int index = alphabets.indexOf(upperCurrChar);
			if(index != -1)
			{
				counter[index]++;
			}
		}
		for(int i=0; i<counter.length; i++)
		{
			System.out.print(counter[i]+" ");
		}
		System.out.println();
		return counter;
	}
	
	public static int maxElement(int[] counter)
	{
		// Initialize maximum element 
        int max = counter[0], maxIndex =0; 
        
        // Traverse array elements from second and 
        // compare every element with current max   
        for (int i = 1; i < counter.length; i++) 
        {   if (counter[i] > max)
        	{
                max = counter[i];
                maxIndex = i;
        	}
                System.out.print(maxIndex+" ");
        }	
       
        return maxIndex; 
	}
	
	public static String decrypt(String str)
	{
		//CeaserCipher ccCeaserCipher = new CeaserCipher();
		int[] count = countElements(str);
		int max = maxElement(count);
		System.out.println(max+" ");
		int dKey = max - 4;
		if(max<4)
		{
			dKey = 26 - (4-max);
		}
		System.out.println(dKey);
		return encrypt(str, 26 - dKey);
	}
	
	public static String encrypt(String s, int key)
	{
		//Making a StringBuilder with a message(encrypted)
		StringBuilder encrypted = new StringBuilder(s);
		//Writing down the alphabets
		String alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		//Compute the shifted alphabet
		String shiftedAlphabets = alphabets.substring(key) + alphabets.substring(0, key);
		for(int i=0; i<encrypted.length(); i++)
		{
			char currChar = encrypted.charAt(i);
			char upperCurrChar = Character.toUpperCase(currChar);
			int index = alphabets.indexOf(upperCurrChar);
			if(index != -1)
			{
				char newChar = shiftedAlphabets.charAt(index);
				if(Character.isLowerCase(currChar))
				{
					newChar = Character.toLowerCase(newChar);
				}
				encrypted.setCharAt(i, newChar);
			}
		}
		return encrypted.toString();
	}
	
	public static void main(String[] args)
	{
		String testString = "<NAME>";
		System.out.println(decrypt(testString));
	}
}
