Question

C code: hash program (use the Fowler-Noll-Vo (FNV) hash algorithm) This is a simple program that...

C code: hash program (use the Fowler-Noll-Vo (FNV) hash algorithm)

This is a simple program that you will use in the second part of the assignment. Details of this program is as follows.
A hashing algorithm is simply an algorithm that maps data of an arbitrary size into a hash value of a fixed size. On your VM, you should have a program called ”md5sum”, which computes the MD5 hash of a file (or bytes taken from standard input). One of the most useful things about md5sum is that it allows you to quickly check if two files are identical; it is highly improbable that two different files will have the same md5 hash (while it is certainly possible, you can safely assume that will not happen in our class).

Note that you will not use md5sum in your assignment. Rather, in this assignment, you will implement and use the Fowler-Noll-Vo (FNV) hash algorithm, which is much simpler than MD5. The following outlines the FNV Hash algorithm:

def hash(bytes):
    hash = 0xcbf29ce484222325
    for byte in bytes:
        hash = hash ^ byte
        hash = hash * 0x100000001b3
    return hash

Your program should read from standard input until it reaches an EOF, and output the hash of the bytes it read using your FNV algorithm. You should add your code to hash.c
In the following example, the user typed “ABC”, and then Enter, and then pressed “Ctrl-D” to send the EOF to the program’s standard input:

[jforce@archlinux lab6]$ ./hash
ABC
93a0128ba58da453

The program computed 93a0128ba58da453 as the hash of ‘‘ABC\n’’
Fun fact (Not useful to solve this assignment): Hashes are commonly used in cryptography and computer security. For example, passwords are often hashed before being put into a database; it is never a good idea to store plaintext passwords in a database. Storing plaintext passwords in a database will result in you beingfired. Note that FNV and MD5 hashes are not cryptographically secure.

Start code:

#include <stdio.h>


int main(){
/*
Fill this code in yourself
*/
  
printf("%lx\n", hash);
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

const size_t Prime = 0x100000001b3;
const size_t Seed = 0xcbf29ce484222325;

int main()
{
printf("Hello, World!\n");
char str[20];
unsigned char *bytes;
size_t hash;
while(1) {
printf("Enter string:");
scanf("%[^\n]%*c", str);
printf(":%s:", str);
bytes = (unsigned char*)str;
hash = Seed;
for (int i = 0; i < strlen(str); i++) {
hash = hash ^ bytes[i];
hash = hash * Prime;
//printf("%02X ", bytes[i]);
}
printf("%lx\n", hash);
}
printf("\n:");
return 0;
}

Add a comment
Know the answer?
Add Answer to:
C code: hash program (use the Fowler-Noll-Vo (FNV) hash algorithm) This is a simple program that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and...

    PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and use the multiplication method to generate hash keys. You may use your own linked list code from a previous assignment or you can use a standard sequence container. Partial definitions for the hash table class and a generic data class are provided (C++ and Java versions). You may use them as a starting point if you wish. If you choose to design your own...

  • 1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please...

    1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please note that while a cryptographic hash is quite common in many Bloom Filters, the hashing algorithm to be implemented is a mix of the the following algorithmic models, specifically, a multiply & rotate hash colloquially known as a murmur hash, and an AND, rolale, & XOR hash colloquially known as an ARX hash. 2 Requirements • Inputs. Read the input file which contains strings...

  • Cryptographic hash functions are very commonly used in password verification. For example, when you use any...

    Cryptographic hash functions are very commonly used in password verification. For example, when you use any online website which requires a user login, you enter your E-mail and password to authenticate that the account you are trying to use belongs to you. When the password is entered, a hash of the password is computed which is then sent to the server for verification of the password. The passwords stored on the server are actually computed hash values of the original...

  • COSC 359 User Authentication Description A widely used password security technique is the use of hashed...

    COSC 359 User Authentication Description A widely used password security technique is the use of hashed passwords and a salt value. This scheme is found on virtually all UNIX variants as well as on a number of other operating systems as shown in Figure 3.1 bellow. To load a new password into the system, the user selects or is assigned a password. This password is combined with a fixed-length salt value. In older implementations, this value is related to the...

  • This should be in Java Create a simple hash table You should use an array for...

    This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...

  • Retrieve program randomAccess.cpp and the data file proverb.txt from the Lab 14 folder. The code is as follows: #include...

    Retrieve program randomAccess.cpp and the data file proverb.txt from the Lab 14 folder. The code is as follows: #include <iostream> #include <fstream> #include <cctype> using namespace std; 327 int main() { fstream inFile("proverb.txt", ios::in); long offset; char ch; char more; do { // Fill in the code to write to the screen // the current read position (with label) cout << "Enter an offset from the current read position: "; cin >> offset; // Fill in the code to move...

  • Implement in Go language AES encryption mode CBC with providing the packages name for Go language....

    Implement in Go language AES encryption mode CBC with providing the packages name for Go language. You can implement AES-ECB Mode (the basic AES) from crypto/aes package and crypto/cipher.Block. You can also get the SHA-256 hash function from crypto/sha256. You can get the secure random numbers generator from crypto/rand package. However, the you will implement both CBC mode and HMAC from scratch. You are NOT allowed to use any libraries or packages to implement these two things for you. You...

  • Ques) Write a program in c, which meets the following requirements. Requirements 1. Read integer values...

    Ques) Write a program in c, which meets the following requirements. Requirements 1. Read integer values from stdin, separated by one or more spaces or newlines, until reaching EOF 2. The input is guaranteed to be well-formed. 3. The input contains no more than 80 values. 4. on standard output, render a simple vertical column graph representation of the input values, in order left to right, using hash'#' characters as shown in the examples below. The number of hashes printed...

  • Please don't use a void fuction and this is a c++ question. Thanks Write a program...

    Please don't use a void fuction and this is a c++ question. Thanks Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below Using...

  • Overview: The goal of this assignment is to implement a simple spell checker using a hash...

    Overview: The goal of this assignment is to implement a simple spell checker using a hash table. You will be given the basic guidelines for your implementation, but other than that you are free to determine and implement the exact classes and methods that you might need. Your spell-checker will be reading from two input files. The first file is a dictionary containing one word per line. The program should read the dictionary and insert the words into a hash...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT