Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!