Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

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

  2. #22
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

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

  3. #23
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by joshdgreen View Post
    I think I'll go ahead and call this one: Solved.

    REP + 1 to all that helped. Thanks.
    Cool; now may I suggest the following variant of the key encryption alphabet to strengthen the encryption somewhat:

    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);
    	}
    kind regards,

    Jos

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Efficiency of code...
    By Inventor22 in forum New To Java
    Replies: 6
    Last Post: 09-26-2010, 11:24 AM
  2. URLConnection Efficiency
    By Lil_Aziz1 in forum New To Java
    Replies: 22
    Last Post: 08-19-2010, 07:27 PM
  3. An Efficiency Question
    By Revenna in forum Java 2D
    Replies: 0
    Last Post: 06-25-2010, 08:22 AM
  4. cryptography
    By swathi palla in forum AWT / Swing
    Replies: 2
    Last Post: 02-19-2009, 02:51 AM
  5. method efficiency
    By TheWave in forum Advanced Java
    Replies: 0
    Last Post: 02-13-2008, 05:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •