Encryption -- Custom algorithm

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Encryption -- Custom algorithm

 
0
  #1
Mar 18th, 2005
I'm trying to write this method that takes some parameters from my text editor, and encrypt the text. I got part of it written, but I'm stuck on the next bit.

I got the part where you convert the "key", but I just can't figure out what to do next.
  1. import java.util.*;
  2.  
  3. public class Encryptor
  4. {
  5. public String encryptText(String key, String text)
  6. {
  7. String finalResult = "";
  8.  
  9. for (int i=0; i<key.length(); i++)
  10. {
  11. long convert = (long)key.charAt(i);
  12. convert *= 128;
  13. finalResult += convert;
  14. }
  15.  
  16. Random randomNumGenerator = new Random(keyResult);
  17. String returnString = "";
  18.  
  19.  
  20. return returnString;
  21. }
  22. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 53
Reputation: aj.wh.ca is an unknown quantity at this point 
Solved Threads: 1
aj.wh.ca aj.wh.ca is offline Offline
Junior Poster in Training

Re: Encryption -- Custom algorithm

 
0
  #2
Mar 19th, 2005
Originally Posted by server_crash
I'm trying to write this method that takes some parameters from my text editor, and encrypt the text. I got part of it written, but I'm stuck on the next bit.

I got the part where you convert the "key", but I just can't figure out what to do next.
  1. import java.util.*;
  2.  
  3. public class Encryptor
  4. {
  5. public String encryptText(String key, String text)
  6. {
  7. String finalResult = "";
  8.  
  9. for (int i=0; i<key.length(); i++)
  10. {
  11. long convert = (long)key.charAt(i);
  12. convert *= 128;
  13. finalResult += convert;
  14. }
  15.  
  16. Random randomNumGenerator = new Random(keyResult);
  17. String returnString = "";
  18.  
  19.  
  20. return returnString;
  21. }
  22. }
Hi,
Your post is not clear. What exactly are you trying to do. You want to encrypt text and for that you have a key, right. You can use XOR alogo to encrypt your text. If you are following a specific algorithm let me know. I am not able to understand where exactly you are stuck up ?

cheers,
aj.wh.ca
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Encryption -- Custom algorithm

 
0
  #3
Mar 19th, 2005
Ok, I got the first part which is where you get the "encryption key" from the user, and convert it to a long. The second part, is actually encrypting the text using the random class, and the new converted key as the seed. I'm not following any alogorithm, im trying to come up with my own.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Encryption -- Custom algorithm

 
0
  #4
Mar 19th, 2005
Here's a short example of how to shift the text one letter over. I'm trying to do something similar to this, except using a key(the seed), and using random values.

  1. public class CeaserCypher
  2. {
  3. public String shiftOne(String text)
  4. {
  5. long convert = 0;
  6. String finalResult = "";
  7.  
  8. for (int i=0; i<text.length(); i++)
  9. {
  10. convert = (long)text.charAt(i) +1;
  11. finalResult += (char)convert;
  12. }
  13.  
  14. return finalResult;
  15. }
  16. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC