0% found this document useful (0 votes)
38 views

Code

This Java code takes in an encrypted string and a shift value as input. It then decrypts the string by shifting each character back by the shift value. It handles wrapping characters from Z to A. The code is split into input, calculation, and display methods. It takes a coded text as input, decrypts it based on the shift, and displays the original text output.

Uploaded by

Varun Sudarsanan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Code

This Java code takes in an encrypted string and a shift value as input. It then decrypts the string by shifting each character back by the shift value. It handles wrapping characters from Z to A. The code is split into input, calculation, and display methods. It takes a coded text as input, decrypts it based on the shift, and displays the original text output.

Uploaded by

Varun Sudarsanan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Qn.

Coding

2003 Question 2

import java.io.*;

class Code

String s;

int l;

int shift;

String code="";

public void input()throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the coded text (characters less than 100) : ");

s=br.readLine();

l=s.length();

if(l>100)

System.out.println("Character limit exceeded");

System.exit(0);

s=s.trim()+" ";

System.out.println("Shift value :");

shift=Integer.parseInt(br.readLine());

if(shift>26)
{

System.out.println("INPUT: "+s);

System.out.println("INVALID SHIFT VALUE");

System.exit(0);

public void calc()

for(int i=0;i<l;i++)

int p='Q'+shift;

if(p>90)

p=64+(p-90);

if(((i+1))<l&&(s.charAt(i)==(char)p)&&(s.charAt(i+1)==(char)p))

code=code+" ";

i++;

else

char k=s.charAt(i);

if(Character.isUpperCase(k))

int t=k-shift;

if(t<65)
{

t=91-(65-t);

code=code+(char)t;

else

code=code+(char)t;

public void display()

System.out.println("INPUT: "+s);

System.out.println("\t\t\tShift : "+shift);

System.out.println("OUTPUT: "+code);

public void main()throws IOException

input();

calc();

display();

}
OUTPUT

Enter the coded text (characters less than 100) :

KPKPRRDIBSMFTRRYBWJFS

Shift value :

INPUT: KPKPRRDIBSMFTRRYBWJFS

Shift : 1

OUTPUT: JOJO CHARLES XAVIER

You might also like