Adam Stever

Greenhorn
+ Follow
since Jul 23, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Adam Stever

Thank you Winston and Ritchie and everybody else who input on my post, your input helped me alot, I ended up using the last format that ritchie gave, and utilized (due to the fact that I had to use information from "the book" I went with if statements with try catch, in both statements. Thank you for your help, I appreciate your tolerance and look forward to more posting.
11 years ago
Is your inadvertant mistake, missing the "a" in private? or is it the private instead of public? And yes I know my programming is very rough around the edges, I know that I am not as refined as some maybe even most but I try hard. What I would like to do is to read the file that is input, into an array list, Which I think that I have done, then later I will increment the file +1, I am having trouble in the else statement, and the decrement part of it. Here are some of the most recent chages/additions to my program.



11 years ago
Thank you for the heads up, My apologies. So what I am trying to do with this program is give the user the option to either encrypt or decrypt their file that they are going to enter. I am trying to do this using a while loop, for loop, if and else statements, Here is what I have so far,



I have asked the user to enter 1 to encrypt their code or 2 to decrypt their code. Thus, if 1 then carry out the function of 1, else...........
A second issue I am having is I am reading in the users file as a string, and java is saying I need to put it into an array, here is what I have,


I am under the impressiong that the file would be in an array due to the fact that I am reading the file that is entered into the array string? Obviously I am wrong, please help me...
11 years ago
I am posting a program that needs some obvious attention, My goal here is to prompt the user wether they would like to encrypt or decrypt their file and obviously just incement by 1, Please help.

11 years ago
Okay, so this is a program that I am trying to write, and the goall here is to give the user an option to ecrypt or decrypt their file, and the form of encryption that I would like to use is just incrment +1 and just move letters by (Obvously) I know that this program is not working I am asking for help and insight into what I need to change and improve. Please offer any advice into which direction I need to keep moving please.





import java.util.*;
import java.io.*;
import java.util.InputMismatchException;

public class FileFun{

public static void main (String[]args){

PrintWriter fileOut; // print out to a file
Scanner fileIn; // to read a file in
Scanner console = new Scanner (System.in);
String fileName = ""; // variable that allow us to store the file name
String line = ""; // enable us to read one line at a time
int function = 0;// 1 to encrypt 2 to decrypt
char ch[]; // temp storing for each character
ArrayList<String> name = new ArrayList<String>(); // stores multiple characters and assists in ecrypting and decrypting

try{
// get file name and either encrypt or decrypt
System.out.println("Please enter a file name");
fileName = console.nextLine();
System.out.println("Would you like to Encyrpt or Decrypt your file? \n Press 1 to Encrypt or 2 to Decrypt");
function = console.nextInt();
fileIn = new Scanner (new FileReader (fileName));
fileOut = new PrintWriter("Java Encrypt/Decrypt");

if (function == 1)

while (fileIn.hasNextLine())
{
line = fileIn.nextLine();

for (int i=0; i<fileName.length(); i++)
{
if (fileName [i] = ch);

{
System.out.println(fileName [i+1]);
}

else (fileName!= ch);
{
System.out.println(fileName [i-1]);
}
}// end for

}// end while

fileOut.close();

}// end try
catch (FileNotFoundException e)
{
System.out.println("Error:" + e.getMessage());
}


}// end main

}// end class
11 years ago
So judging from information that I am finding via books and online, wouldn't my encrypt and decrypt function go after the if statement? Due to the fact that this function is after every character is going to be read in and the encrypt and decrypt functions should take place here correct? I am just trying to piece this thing together, I have the program running so that at this point the program will eliminate the whitespace (obviously) however I am struggling on how to input the encrypt and decrypt functions, and where they would go. Usually the user would know if the file is encrypted or not, but what I am looking for is how to decrypt if the file is encypted and encrypt if the file is decrypted. Please help.
11 years ago
I absolutley love the information that people are offering in this forum. However, I have a couple more questions, which is I like the char example, but where would that get written into my code? It would have to be in side the the try, yes? and then instead of the [c] in the public char [c] would I insert the file name that needs to be encrypted and decrypted? and then my second question, is how to I import the ASCII tables, and how would i write them into the code? I understand that I would be working with 128 characters as opposed to 65,000. I am having trouble containg my excitement with all this great information. The help that I have received so far is great. I know that everybody may not be as undestanding of a "Greenhorn " but I do appreciate the ones who are.
11 years ago
Well what I need to do is write my own encryption and decryption funtion into this program. I used the eliminating white space just as a "practice". What I would like to do is use ASCII and increment the letters to shift. I just don't know where to insert these functions into this program. If I have my understanding correctly, the ArrayList will assist in encrypt and decrypt correct? I have a couple different examples that I can give too.

char ch = ...
if (ch >= 'A' && ch < 'Z') ch++;
else if (ch == 'Z') ch = 'A';
else if (ch >= 'a' && ch < 'z') ch++;
else if (ch == 'z') ch = 'z';

My question on this little method is how would I decrypt? Then I have this one,

Assuming I want to shift all letters by n:
((letter - 'A' + n) % 26) + 'A'

And to decode:
((letter - 'A' + 26 - n) % 26) + 'A'

where would I insert these lines of code? I am just trying different ways of encrypt and decrypt am open to suggestion

I am thinking that the char method would work better for the code that I have written so far correct?
11 years ago
I am trying to write a program that asks a user for a file. I need to encrypt and or decrypt the text that is input. I don't know if I need to import another class, or if I can just write a line or two of code that has Encrypt.txt and Decrypt.txt I have attached what I have so far, please feel free to help me where I am going wrong. Thank you in advance.
11 years ago