Java Ascii Code Message Scrambler

If you wish to post tutorials or need help with any web programming language that isnt listed above then please post them in here.
1 post Page 1 of 1
Contributors
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 444
Joined: Tue Feb 16, 2010 6:24 am

Java Ascii Code Message Scrambler
Livengood
Well hello everyone, i know i havent been on in awhile. I going to share a project i had to do in class, this was a simple little did in like 25 mins.
Code: Select all
import java.util.Scanner;
public class Array_Program_4 {
	/*** Austin Livengood ***/
	public static void main(String[] args) {
		String phraseMe=null, exitstring;
		char exitchar;
		char[] stringArray=null, bstringArray=null;
		Scanner scan = new Scanner(System.in);
		exitchar='y';
		int Choice=0;
		boolean check=false;
		do{
			check = false;
			while(check == false){
				try{
					System.out.println("Press 1 for Converstion to encode" + " or " + "Press 2 for Converstion to Phrase");
					Choice=scan.nextInt();
					check = true;
				}//End Try
				catch(Exception InputMismatchError){
					System.out.println("Sorry, that is not a valid number!");
					scan.nextLine();
				}//End Catch
			}//End While
			scan.nextLine();
			if(Choice==1){
				System.out.println("Enter a Phrase.");
				phraseMe=scan.nextLine();
				
				stringArray=phraseMe.toCharArray();
				bstringArray=new char[stringArray.length];
				
				int getMe=0, Space=32;	
				for(int i=0; i < stringArray.length; i++){
					getMe=(int)stringArray[i];
					if(getMe==Space){
						bstringArray[i]=(char)Space;
					} else if(getMe==89) {
						bstringArray[i]=(char)65;
					} else if(getMe==90) {
						bstringArray[i]=(char)66;
					} else if(getMe==121) {
						bstringArray[i]=(char)97;
					} else if(getMe==122) {
						bstringArray[i]=(char)98;
					} else {
						getMe=getMe + 2;
						bstringArray[i]=(char)getMe;
					}
				}
				String PhraseToString = new String(bstringArray);
				System.out.println("Original Message: " + phraseMe);
				System.out.println("Encoded Message: " + PhraseToString);
			} else {
				System.out.println("Enter an Encoded Phrase.");
				phraseMe=scan.nextLine();
				
				stringArray=phraseMe.toCharArray();
				bstringArray=new char[stringArray.length];
				
				int getMe=0, Space=32;	
				for(int i=0; i < stringArray.length; i++){
					getMe=(int)stringArray[i];
					if(getMe==Space){
						bstringArray[i]=(char)Space;
					} else if(getMe==65) {
						bstringArray[i]=(int)89;
					} else if(getMe==66) {
						bstringArray[i]=(char)90;
					} else if(getMe==97) {
						bstringArray[i]=(char)121;
					} else if(getMe==98) {
						bstringArray[i]=(char)122;
					} else {
						getMe=getMe - 2;
						bstringArray[i]=(char)getMe;
					}
				}
				String PhraseToString = new String(bstringArray);
				System.out.println("Encoded Message: " + phraseMe);
				System.out.println("Message: " + PhraseToString);
			}
			
			System.out.println("Would you like to convert Encode another message?");
			exitstring=scan.next();
			exitchar=exitstring.charAt(0);//Get First Letter
		} while (exitchar == 'Y' || exitchar == 'y');
	}

}
Original Message: Hello codenstuff!
Encrypted Message: Jgnnq eqfgpuvwhh#

This is a simple code that will change each little letter and load them into an array to be converted its simple. Also built with a do while that goes around, that will re run if you type yes.
Image
1 post Page 1 of 1
Return to “Other Languages”