0

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
3
  • Don't repost your question... Commented Oct 24, 2013 at 4:29
  • i was told i should make a new question if it is a different problem? sorry i'm new here. but the decryption is not shifting the letters by 6. g -> u = 14 Commented Oct 24, 2013 at 4:30
  • The code example is largely incomplete, can you post more? Commented Oct 24, 2013 at 5:43

1 Answer 1

2

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);
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.