0

I am trying to create an encryption and decryption program but when I run there is an error. I tried to run my program on Intelli J ide, I also tried on Eclipse but also got the same error, where did I go wrong?

package com.sanfoundry.setandstring;

import java.util.Scanner;

public class AffineCipher
{

    public static String encryptionMessage(String Msg)
    {
        String CTxt = "";
        int a = 3;
        int b = 6;
        for (int i = 0; i < Msg.length(); i++)
        {
            CTxt = CTxt + (char) ((((a * Msg.charAt(i)) + b) % 26));
        }
        return CTxt;
    }

    public static String decryptionMessage(String CTxt)
    {
        String Msg = "";
        int a = 3;
        int b = 6;
        int a_inv = 0;
        int flag = 0;
        for (int i = 0; i < 26; i++)
        {
            flag = (a * i) % 26;
            if (flag == 1)
            {
                a_inv = i;
                System.out.println(i);
            }
        }
        for (int i = 0; i < CTxt.length(); i++)
        {
            Msg = Msg + (char) (((a_inv * ((CTxt.charAt(i) - b)) % 26)));
        }
        return Msg;
    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the message: ");
        String message = sc.next();
        System.out.println("Message is :" + message);
        System.out.println("Encrypted Message is : "
                + encryptionMessage(message));
        System.out.println("Decrypted Message is: "
                + decryptionMessage(message));
        sc.close();
    }


}
  • Does this answer your question? [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – Meninx - メネンックス Jul 24 '21 at 13:33
  • You class is named `com.sanfoundry.setandstring.AffineCipher` not `AffineCipher`. Make sure it is located in the correct directory: `com/sanfoundry/setandstring/AffineCipher.class`. – Robert Jul 24 '21 at 13:36
  • @ThomasHerondale Please don't post multi-line code in comments as it gets totally unreadable. – Robert Jul 24 '21 at 13:37
  • @Robert Can you tell me how, then? I'm kind of struggling... – Thomas Herondale Jul 24 '21 at 13:38
  • Read the question and it's answers Meninx has posted, they you may understand what directory structure is required. For beginners I would recommend to remove the `package ...` line in your code, then you can do everything in one directory. – Robert Jul 24 '21 at 13:40
  • Err... I'm not the author of the question... I was asking how to correctly put multiline-code here – Thomas Herondale Jul 24 '21 at 13:43
  • @ThomasHerondale: Well you can't in comments... – helvete Jul 24 '21 at 14:50

0 Answers0