Hash a txt file using arduino

Post Reply
User avatar
NuwanSenanayake
Posts: 2
Joined: Tue Jun 25, 2013 8:24 pm

Hash a txt file using arduino

Post by NuwanSenanayake » Tue Jun 25, 2013 8:29 pm

i want to hash a txt file using arduino, im doing a somekind of data logging project,,,, please help me to do that,,,, thanks
:clap:
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Hash a txt file using arduino

Post by Neo » Tue Jun 25, 2013 9:25 pm

To start with, tell us your Arduino platform and the peripherals that you have connected. Especially I would like to know about the SD card interface to the micro.
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: Hash a txt file using arduino

Post by SemiconductorCat » Tue Jul 02, 2013 4:39 am

BUMP: @Nuwan
Are you there?
would you able to find the library/algorithm which works?
Would you able to make it work?

As neo told , there are libraries for hashing like MD5, but some are not
support on some hardware. That's why he need to know.So it varies.
User avatar
NuwanSenanayake
Posts: 2
Joined: Tue Jun 25, 2013 8:24 pm

Re: Hash a txt file using arduino

Post by NuwanSenanayake » Tue Jul 02, 2013 5:46 pm

im still stuck with my algorithm, if you watch that video you can get a rough idea
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: Hash a txt file using arduino

Post by SemiconductorCat » Tue Jul 02, 2013 7:03 pm

Code: Select all

void loop()
{
  bool newdata = false;
  unsigned long start = millis();
  
  // Every second we print an update
  while (millis() - start < 1000)
  {
    if (feedgps())
      newdata = true;
  }
  
  gpsdump(gps);
  
  //Write the newest information to the SD Card
  dataString = SD_date_time + "," + SD_lat + "," + SD_lon;
  if(SD_date_time != "invalid")
    digitalWrite(LED, HIGH);
  else
    digitalWrite(LED, LOW);
    
  //Open the Data CSV File
  File dataFile = SD.open("LOG.csv", FILE_WRITE);
  if (dataFile)
  {
    dataFile.println(dataString);
    Serial.println(dataString);
    dataFile.close();
  }
  else
  {
    Serial.println("\nCouldn't open the log file!");
  }
}

Are you prefer to use MD5 as hashing or you need your own algorithm ? Hashing a file is simple.
Simply you just open the file using stdio libs and read it calculate the hash and write another file
with the same name called "LOG.md5". So you could check it from your software/matlab or whatever
you prefer. Is that you need? [sorry I could not watch the video, may be neo will help you on this].

if so each write you made into the fie , you need to recalculate it's MD5 and write it back to LOG.md5
file. Anyway it would be a lengthy operation. If we have support to memory mapped files in ardino
then it would be more faster than this. But I don't think ardino would support such features because it's
limited memory. May be not MD5, what about a simple algorithm like CRC? You need that for checking
data integrity right?

Or what about append the hash filed for every record? May be that would work.So you need to change.

Code: Select all

dataString = SD_date_time + "," + SD_lat + "," + SD_lon;
String hash = hash_algo(dataString);
dataString = dataString + " " + hash ;

depending on your hash algorithm , if that emits escape characters or white-spaces you may need some
modifications to this above code.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Hash a txt file using arduino

Post by Neo » Wed Jul 03, 2013 2:37 pm

i use icsp interface to connect my sd card module
As per the product description, the SD card interface board is interfaced to Arduino over SPI port.

Have you been able to access files of SD card yet. I think this is the first this we should do.

Since you seem needing to hash large files, you will have to implement some kind of buffered reading mechanism to hash data chunks. Due to memory limitations, you can't read a whole big file to memory. May be 128 bytes at a time is fine.
Post Reply

Return to “Arduino”