Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CONVERT THE FOLLOWING CODE TO C++ import java.io.*; class Chegg { public static void encrypt(String str,String key[]) throws UnsupportedEncodingException { byte [] st = null

CONVERT THE FOLLOWING CODE TO C++

import java.io.*; class Chegg { public static void encrypt(String str,String key[]) throws UnsupportedEncodingException { byte[] st = null; st = str.getBytes("UTF-8"); str = ""; for(byte b:st) { str = str + Integer.toBinaryString(b); } int len = str.length(); int s[] = new int[len]; int x[] = new int[19]; int y[] = new int[22]; int z[] = new int[23]; int i; for(i=0; i<19; i++) x[i] = Integer.parseInt(key[i]); for(i=0; i<22; i++) y[i] = Integer.parseInt(key[i+19]); for(i=0; i<23; i++) z[i] = Integer.parseInt(key[i+19+22]); int m = 0, t; for(int j=0; jif(x[8]==y[10] || x[8]==z[10]) m = x[8]; else if(y[10]==z[10]) m = y[10]; if(x[8]==m) { t = x[13]^x[16]^x[17]^x[18]; for(i=18; i>0; i--) x[i] = x[i-1]; x[0] = t; } if(y[10]==m) { t = y[20]^y[21]; for(i=21; i>0; i--) y[i] = y[i-1]; y[0] = t; } if(z[10]==m) { t = z[7]^z[20]^z[21]^z[22]; for(i=22; i>0; i--) z[i] = z[i-1]; z[0] = t; } s[j] = x[18]^y[21]^z[22]; } int enc[] = new int[len]; System.out.println(" The encrypted message is:"); for(i=0; iparseInt(Character.toString(str.charAt(i)))^s[i]; System.out.print(enc[i]); } } public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the string to be encrypted:"); String msg = br.readLine(); System.out.println(" Enter the 64 bit key"); String key[] = br.readLine().split(""); encrypt(msg,key); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions

Question

Does advertising affect our value system? In what ways?

Answered: 1 week ago