• Topic Archived
You're browsing the GameFAQs Message Boards as a guest. Sign Up for free (or Log In if you already have an account) to be able to post messages, change how messages are displayed, and view media in posts.

User Info: Kyoto

Kyoto
11 years ago#1
/**
* A program to search for to encrypt and decrypt lines of text. See
* CaesarCipher.txt TODO: Put your netids (i.e. username) in the line below
*
* @author justin is a poop
*/
public class CaesarCipher {

public static void main(String[] strings) {

Boolean Offset=true;
Boolean Runner=true;
int OffNum = 0;
char z = 0;
char z2 = 0;

while(Runner == true){
String lol = ("");
String enc = ("");

while(Offset){
TextIO.putln("Please enter the shift value (between -25..-1 and 1..25)");
OffNum = TextIO.getlnInt();
lol = ("");


if(OffNum == 999 || OffNum == -999){
TextIO.putln("Using position shift");
Offset = false;
}

else if(OffNum > 25 || OffNum == 0 || OffNum < -25){
TextIO.putln(OffNum + " is not a valid shift value.");
}

else{
TextIO.putln("Using shift value of " + OffNum);
Offset = false;
}
}

TextIO.putln("Please enter the source text (empty line to quit)");
enc = TextIO.getln();


if(enc.equals("")){
TextIO.putln("Bye.");
Runner = false;
}

else
TextIO.putln("Source :" + enc);
enc = enc.toUpperCase();


if(OffNum == 999){
for(int q = 0; q < enc.length(); q++){
z2 = enc.charAt(q);


//z2 -= (z2 % 26);

if (z2 >= 32 && z2 <= 64){
lol += z2;
}



else{
int temp = q;
while(temp>25){
temp = (temp-26);
}


z2 += temp;




if (z2 > 'Z'){
z2 -= 26;
}
else if (z2 < 'A'){
z2 += 26;
}

lol += z2;
}
}
}

else if(OffNum == -999){
for(int q = 0; q < enc.length(); q++){

z2 = enc.charAt(q);

if (z2 >= 32 && z2 <= 64){
lol += z2;
}

else{
int temp = q;
while(temp>25){
temp = (temp-26);
}

z2 -= temp;

if (z2 > 'Z'){
z2 -= 26;
}
else if (z2 < 'A'){
z2 += 26;
}

lol += z2;
}
}
}



else


for(int k = 0; k < enc.length(); k++){
z = enc.charAt(k);
if (z >= 32 && z <= 64){
lol += z;
}
else {
z += OffNum;

if (z > 'Z'){
z -= 26;
}
else if (z < 'A'){
z += 26;

}
lol += z;

}
}


if(Runner == true){
TextIO.putln("Processed:" + lol);
}
}
}
}

User Info: SurgeFox

SurgeFox
11 years ago#2
Bizarre. That annoying little red text in the corner is...O_O
~Bunny!~ ~funny~
Hardcore™ - We'll probably be modded for this...
  • Topic Archived