lainconnors

Arduino Hash Cracker Sketch.ino

Oct 21st, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <MD5.h>
  2. char returnVal[33]; //An MD5 hash is ALWAYS 32 characters long, or 128bit. Add an extra byte for null-termination.
  3. char buf[64]; //The max Serial buffer is 64 bytes.
  4.  
  5. void setup() {
  6.   pinMode(2, INPUT_PULLUP); //Unnecessary at the moment, will be needed later.
  7.   Serial.begin(115200);
  8.   //delay(1000); //A second to start up properly.
  9. }
  10.  
  11. void clearBuffer(){
  12.   for (int i = 0; i < 64; ++i){
  13.     buf[i] = 0x00;
  14.   }
  15. }
  16.  
  17. void hashMD5(char a[]){
  18.   unsigned char* hash = MD5::make_hash(a);
  19.   char *md5str = MD5::make_digest(hash, 16); //Direct example from Tzikis's GitHub.
  20.   for(int i = 0; i < 32; ++i){
  21.     returnVal[i] = md5str[i]; //Assigning the global variable character by character.
  22.   }
  23.   returnVal[32] = 0x00; //Always null-terminate your strings, kids!
  24.   free(hash); //Since we're looping, we need to free up the memory before another iteration.
  25.   free(md5str);
  26. }
  27.  
  28. void loop() {
  29.   clearBuffer();
  30.   if(Serial.available()){
  31.       Serial.readBytesUntil('\n', buf, 64);
  32.       if(buf){
  33.           hashMD5(buf);
  34.           Serial.print(returnVal);
  35.       }
  36.   }
  37. }
Add Comment
Please, Sign In to add comment