posted 18 years ago
I am making a program where you will be asked if you would wish to scramble a program, if you click yes, it brings you to another question on which file you wish to upload, it uploads the file, but it wont scramble it, and I have all the coding in there from two programs I made, one to ask the questions, and one to scramble the document, and when I tried putting them in there together it wouldnt work, I was wondering what the problem might be on this, and the only way to show you is with the code, so here is a bit of my code.
___________________________________________________________________________
import java.io.*;
public class CipherCipher
{
public static void main (String[] args) throws Exception
{
FileInputStream File1; //create a file to input
DataInputStream In; //create an Input stream
String temp = ""; //create a string to temerarily store data
FileOutputStream Fileout; // create a file to output
PrintStream p; //create a print stream
//Time to define the variables
int lengthOf;
int temp2 = 0;
char[] temp3;
String Encode = "";
String Decode = "";
String Input = "";
String Inputb = "";
String temp4 = "";
String temp5 = "";
String yes = "";
String a = "a";
String b = "b";
String filename = "";
String fileInput = " ";
DataInput keyboard = new DataInputStream (System.in);
//Figuring out if you would like to encode something, or decode something.
{
System.out.println ("Would you like to scramble your document? (y for yes, n for no):");
temp4 = keyboard.readLine ();
Input = temp4;
}
if (Input.startsWith ("Y") || Input.startsWith ("y"))
{
//Storing the user input to "filename" so the program can retrieve the file you wish to see
System.out.println ("Which file would one wish to scramble? (*bobdole.txt is for you sefeldas*) ");
filename = keyboard.readLine ();
File1 = new FileInputStream (filename);
In = new DataInputStream (File1);
{
/*This is the functionality of the program, where it takes every letter, lower case and upper case, is being converted
fromitsnatrualstatetoastateinwhichisrandom.Thisway, once it is scrambled, noone who catches onto it can read it
unlesstheyhavethedecoder*/
Fileout = new FileOutputStream ("scrambled.txt"); //Where the data to which is scrambled is stored
p = new PrintStream (Fileout);
while (In.available () > 0)
{
temp = In.readLine ();
lengthOf = temp.length ();
temp3 = temp.toCharArray ();
for (temp2 = 0 ; temp2 < lengthOf ; temp2++)
{
if (temp3 [temp2] == ('a')) //If the letter is <-- it will be changed to...
{
p.println ("J"); //...this in the output scrambled.txt
}
/*From here on out, the past two comments follow the exact same pattern with different letters, and or characters*/
else if (temp3 [temp2] == ('b'))
{
p.println ("a");
}
else if (temp3 [temp2] == ('c'))
{
p.println ("m");
}
...
...
...
else if (temp3 [temp2] == ('7'))
{
p.println ("0");
}
else if (temp3 [temp2] == ('8'))
{
p.println ("P");
}
else if (temp3 [temp2] == ('9'))
{
p.println ("r");
}
else if (temp3 [temp2] == ('0'))
{
p.println ("R");
}
else if (temp3 [temp2] == (' '))
{
p.println ("!");
}
else if (temp3 [temp2] == ('!'))
{
p.println (".");
}
else if (temp3 [temp2] == ('.'))
{
p.println ("_");
}
else if (temp3 [temp2] == (','))
{
p.println ("*");
}
fileInput = In.readLine ();
System.out.println (fileInput);
}
}
}
}
{
if (Input.startsWith ("N") || Input.startsWith ("n") || Input.startsWith ("Y") || Input.startsWith ("y"))
{
System.out.println ("Would you like to unscramble your document? (y for yes, n for no):");
temp5 = keyboard.readLine ();
Inputb = temp5;
}
if (Inputb.startsWith ("N") || Inputb.startsWith ("n"))
{
System.out.println ("You typed: " + Inputb);
}
else
//Storing the user input to "filename" so the program can retrieve the file you wish to see
System.out.println ("Which file would one wish to unscramble? (*bobdole.txt is for you sefeldas*) ");
filename = keyboard.readLine ();
File1 = new FileInputStream (filename);
In = new DataInputStream (File1);
while (In.available () > 0)
{
fileInput = In.readLine ();
System.out.println (fileInput);
}
System.out.println ("You typed: " + Input);
}
}
}
Inbetween where the ... lines are is the same coding for all letters and numbers, I would appreciate the help
When in doubt, get the hammer!