Goodmorning Mr. Phelps, your mission is to implement a code that is secure enoug
ID: 3581348 • Letter: G
Question
Goodmorning Mr. Phelps, your mission is to implement a code that is secure enough t hat you can be communicated with openly. Yet no one, including other agents of the IMF, can decode. Your are to begin by multiplying your age (in years) by your birth month by your birth clay and reducing them mod 6 and then add 1. Your code to expand is then given above. You must encode THIS (8) IS PROOF!" and then demonstrate the decode. Below you will find the standard ANSI table to initialize your message. As always, should you or any of your I.M. Force be caught or killed, the Secretary will disavow any knowledge of your actions. This letter will not self-destruct as is normal due to a limited supply of flash paper. This will be resolved in the future." It is recommended to choose the largest number-length to encode your message. Example suppose you have ANSI translated and got 234 112 034 023 then you could choose 3 digit as given or as 4 digits ie 2341 1203 4023 or as 5 digit 23411 20230 etc... (warning: the last number may not be the correct length and you need to come up with a padding scheme. Think extra useless characters in your message.)Explanation / Answer
SOURCE CODE:
public class encodeAlgo {
private static String encode(String a)
{
String temp="";
int len=a.length(),A=0,i=0;
while(i<len)
{
A=(int)(a.charAt(i++));
if(A<100)
temp=temp+"0"+A;
else
temp=temp+A;
}
int max=0;
for(i=0;i<temp.length();i++)
if(max<Integer.parseInt(temp.charAt(i)+""))
max = Integer.parseInt(temp.charAt(i)+"");
while((temp.length()%max)!=0)
temp=temp+"0";
String ret="";
while(!temp.isEmpty())
{
ret=ret+" "+temp.substring(0, max);
temp=temp.substring(max);
}
return ret;
}
private static String decode(String a)
{
a=a.replaceAll(" ", "");
String temp="";
char c;
int len=a.length(),i=0,t=0;
while((i+3)<=len)
{
t=Integer.parseInt(a.substring(i,i+3));
c=(char)t;
temp=temp+c;
i=i+3;
}
return temp;
}
public static void main(String args[])
{
System.out.println("Encoded Message: "+encode("THIS (8) IS PROOF!"));
System.out.println("Decoded Message: "+decode(" 084072073 083032040 056041032 073083032 080082079 079070033"));
}
}
OUTPUT:
Encoded Message: 084072073 083032040 056041032 073083032 080082079 079070033
Decoded Message: THIS (8) IS PROOF!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.