CyberArmy University | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

RE: The working version (TM) :)


[Replies] [Reply] [View by Thread] [Help]
[Back To SNEAK Development Forum]

Posted by Lt CyberTNT On 2005-03-18 15:05:54
In Reply to The working version (TM) :) Posted by Maj anvar On 2005-03-18 14:33:00

LtLt
Lt CyberTNT


Looks good except the exception handeling and your trimming of whitespace characters. You shouldnt trim the array, as whitespace characters can be hashed too.

On 2005-03-18 14:33:00, anvar wrote
>
>Alright then, here's the working version. Thanks for pointing out that it were all hex value's (I must have been really sleeping back there :)
>I tested it with the tests supplyed at http://faqs.org/rfcs/rfc1321.html and they match, so I believe this version is working properly, although there is maybe some optimalisation to do.
>
>Comments/etc is welcomed. :)
>
>

>package net.cyberarmy.sneak.scheme;

>

>import net.cyberarmy.sneak.Scheme;

>import java.security.MessageDigest;

>

>public class MD5Scheme implements Scheme {

>   public String getNameKey() {

>        return "scheme.MD5.name";

>    }

>

>    public String getDescriptionKey() {

>        return "scheme.MD5.description";

>    }

>

>    /**

>     * Default method to run this.

>     * @param input String -- The string we want to MD5.

>     * @return String -- The result we get.

>     */

>    public String execute(String input) {

>

>      if (input == null) return null;

>      input = input.trim();

>      if (input.length() == 0) return null;

>

>      MessageDigest md = null;

>      try {

>         md = MessageDigest.getInstance("MD5");

>      }

>

>      // Eat the exception because it shouldn't happen.

>      catch (Exception e) {

>        return "Source-code Error";

>      }

>

>      // Get the array of bytes representing the MD5 hash.

>      byte[] bytes = md.digest(input.getBytes());

>      StringBuffer md5 = new StringBuffer();

>      // Loop through the array to get all the bytes, convert 

>      // them to hex, and add them to our string.

>      for (int i = 0; i < 16; i++) {

>        md5.append(String.format("%02x", bytes[i]));

>      }

>       return md5.toString();

>    }

>}

>
>+++++[<++++>-]<++[>+++>++++<<-]>+.>+.<
-.<+++[>+>--<<-]>.>-.>++[<+<++++>>-]<.<+.>.



Replies:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.02348 seconds


About Us | Privacy Policy | Mission Statement | Help