Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vishash: A Hash Function That Generates Easily Recognizable and Comparable Images

When downloading, transferring, or simply manipulating files, it is sometimes necessary to verify their integrity. Typically, special functions are used to calculate the fingerprint of a file. This fingerprint often consists of a relatively short string of characters. To compare two files, the fingerprints of both files are calculated, and if they differ, the files are different. A good fingerprint function also ensures that if the fingerprints are identical, the files are likely the same as well. However, the space of possibilities makes it impossible to guarantee this property with certainty.

The required property is that it should be difficult, for a given file, to find a different file with the same fingerprint.

Such hash functions can also be used for cryptographic applications. In this case, it is also important that, for a given hash, it is impossible to retrieve the original input.

Vishash is a file hashing function, meaning it calculates the fingerprint of any file. However, unlike traditional functions that compute strings of bits (or characters), Vishash generates an image. This unique feature has the advantage of producing a visual fingerprint that is easily recognizable and comparable, unlike a 64-character alphanumeric string, such as the one returned by the SHA3 algorithm.

These advantages would be even more interesting if Vishash possessed the properties of a cryptographic hash function, as described above.

Before measuring the properties of the algorithm, let's present how to use the vishash executable, as well as how the algorithm works.


Demo

If you compute the vishash of this readme file, you will get the following image:

Usage

Vishash v1.0
------------
Vishash is a utility that computes an easily recognizable png image using only the data of any a given file, such that any change in the file produces a completely different image. The image only depends of the input content and the given parameters.
Thanks to its properties, Vishash can help to easily check if two files are the same by comparing their vishash
---

---
Usage:
 bin/vishash <input_file>    for hashing <input_file>
 bin/vishash                 for hashing standard input
---

---
Optional parameters:
 -s | --size   : With parameter size enabled, the image is a square. size corresponds to the length of one side of the image in pixels. (default: 128)
 -w | --width  : Width of the image in pixels. (default: 128)
 -h | --height : Height of the image in pixels. (default: 128)
 -o | --output : Name of the output image. (default: <input_name>.png)
 -K            : K is a constant representing the level of details of the image. 50 is no details and 300 is too much details. (default: 125)
 -j | --jobs   : The maximal number of cores to use during calculation (default: 4)
 -l | --logs   : Display logs
 -h | --help   : Displays this help
---

Algorithm Overview

The Vishash algorithm works in two main parts:

Part 1: Generating a Pseudo-Random Image

The algorithm starts by generating a pseudo-random image based on the input file. The image is filled with pseudo-random numbers, and the file is traversed entirely. If there are more pixels in the image than bytes in the file, the file is traversed again.

The Pseudo-Random Sequence

The pseudo-random sequence used is straightforward, and each number is calculated as follows:

uint32_t next_random_number(void) {
    random_number = (random_number * A + C) % M;
    return random_number;
}

With the following constants:

#define A 16807
#define C 42
#define M (((uint32_t)1 << 31) - 1)

As mentioned earlier, this pseudo-random sequence is calculated from a seed generated using the input file's data. Here is the algorithm that calculates the initial random number:

void init_random_number(uint8_t* file_data, long int size) {
    random_number = 3;
    for (long int i = 0; i < size; i++) {
        random_number = (random_number * A + file_data[i]) % M;
    }
}

This algorithm uses the same constants as those given above.


Part 2: Processing the Pseudo-Random Image into the Final Image

The image processing algorithm can be considered a diffusion algorithm: it works through successive denoising steps.

Here is the function implementing the algorithm (in simplified C):

void make_iterations(FloatImage* img, int taille, int K, int n) {
    for (int i = 1; i < n; i++) {
        double sigma = (double)(i*taille)/(double)K;
        size = kernel_size(sigma);
        img = mean_blur(img, size, sigma);

        img *= 2 + 5*(n-i)/n;
        remove_zero(img);
    }
}

The algorithm iteratively blurs the image and then multiplies each color by a certain constant. As the iterations progress, the blur becomes more aggressive, and the multiplicative constant decreases.

The formulas were determined ad-hoc to ensure that the constant K allows control over the size of the patterns relative to the image.


About

Visual hashing function for hashing files

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages