Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Java Simple Encryptor And Descriptor #163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Java/EncryptorAndDecrptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.Scanner;

public class EncryptorAndDecrptor {
public static void main(String[] args){
int x= 3;
Scanner scan = new Scanner(System.in);

System.out.println("Select the Option \nEncrypter (Enter 1 & Submit) or \nDecrypter(Enter 2 & Submit)");
String selector = scan.nextLine();

switch (selector){
case "1":
System.out.println("Enter the message you want to Encrypt");
String ss = scan.nextLine();

for(int i=0;i<ss.length(); i++) {
if(ss.charAt(i) != ' '){

char c = ss.charAt(i);

if('A'<= c && 'Z'>=c){
int t = ((int)c - 65+x)%26;
System.out.print((char)(65+t));
}else{
int t = ((int)c - 97+x)%26;
System.out.print((char)(97+t));
}

}else System.out.print(" ");
}
break;
case "2":
System.out.println("Enter the message you want to Decrypt");
String ss2 = scan.nextLine();

for(int i=0;i<ss2.length(); i++) {
if(ss2.charAt(i) != ' '){

char c = ss2.charAt(i);

if('A'<= c && 'Z'>=c){
int t = ((int)c -65 -x)%26;
int t2 = t >=0 ? t : 26+t;
System.out.print((char)(65+t2));
}else{
int t = ((int)c -97 -x)%26;
int t2 = t >=0 ? t : 26+t;
System.out.print((char)(97+t2));
}

}else System.out.print(" ");
}
break;
default:
System.out.println("wrong Entry");
}


}
}