Reputation: 63
I'm trying to work on a problem that takes for example abcdef and encrypts it using a numeric key such as 3. that means all letters are shifted 3 letters down to yield defghi
Eventually the program will ask for a textfile input, output textfile, and the key in the commandline.
I'm running into an error with my current code. The encyption is faulty.
import java.util.Scanner;
import java.io.*;
public class Program
{
public static void main(String[] args) throws IOException
{
here is the error:
java Program 1.txt 2.txt 6
Encrypted:ghiJklM
Decrypted:uvwXyzA
Upvotes: 0
Views: 79
Reputation: 1090
You are decrypting the original String
, not the encrypted one.
The first two lines of your decryption algorithm should read:
for(int j = 0; j < encrypted.length(); j++)
{
int current1 = encrypted.charAt(j);
...
Upvotes: 2