Results 21 to 23 of 23
Thread: Cryptography Efficiency
- 10-29-2010, 08:04 AM #21
It worked haha! That was an awesome idea JosAH. Now all I need to do is clean up the code and apply it to the encryption method. Here's the updated decrypt method:
Java Code:package Application; public class Decrypt extends Crypto { public Decrypt(Information word){super(word);} public char[] getFinalArray(String message, char[] encryptedMessage, char[] encryptArray) { String orig = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", enc = ""; for(int j = 0; j < encryptArray.length; j++) enc = enc + encryptArray[j]; for(int i = 0; i < encryptedMessage.length; i++) { char c = decrypt(message.charAt(i), orig, enc); if (c >= 'A' && c <= 'Z') encryptedMessage[i] = c; else if (c == ' ') encryptedMessage[i] = c; } return encryptedMessage; } public char decrypt(char c, String orig, String enc) { if(c == ' ') return c; return orig.charAt(enc.indexOf(c)); } }Sincerely, Joshua Green
Please REP if I help :)
- 10-29-2010, 08:07 AM #22
I think I'll go ahead and call this one: Solved.
REP + 1 to all that helped. Thanks.Sincerely, Joshua Green
Please REP if I help :)
- 10-29-2010, 09:16 AM #23
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Cool; now may I suggest the following variant of the key encryption alphabet to strengthen the encryption somewhat:
kind regards,Java Code:private static void encrypt(char[] enc, String password) { for (int i= 0; i < enc.length; i++) { int t= enc[i]-'a'+password.charAt(i)-'a'; enc[i]= (char)('a'+t%26); } } private static String encryptKey(String password, String dec) { char[] enc= dec.toCharArray(); int n= password.length(); char[] pw= password.toCharArray(); for (int j= 0; j < enc.length; j+= n) { for (int i= 0; i < pw.length; i++) { char t= enc[i+j]; enc[i+j]= enc[pw[i]-'a']; enc[pw[i]-'a']= t; } pw= Arrays.copyOfRange(enc, j+n, Math.min(enc.length, j+2*n)); encrypt(pw, password); n= pw.length; if (n == 0) break; } return new String(enc); }
Jos
Similar Threads
-
Efficiency of code...
By Inventor22 in forum New To JavaReplies: 6Last Post: 09-26-2010, 10:24 AM -
URLConnection Efficiency
By Lil_Aziz1 in forum New To JavaReplies: 22Last Post: 08-19-2010, 06:27 PM -
An Efficiency Question
By Revenna in forum Java 2DReplies: 0Last Post: 06-25-2010, 07:22 AM -
cryptography
By swathi palla in forum AWT / SwingReplies: 2Last Post: 02-19-2009, 01:51 AM -
method efficiency
By TheWave in forum Advanced JavaReplies: 0Last Post: 02-13-2008, 04:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks