I have a directory in my mac which has files with following names -
Directory images - 1.jpg 2.jpg 3.jpg 4.jpg
I would like to write a bash script to rename all the files in this folder, by using some standard hashing algorithm, so that the directory now looks something like this -
Lets assume that the hashing key is common_key = "mykey123"
Directory images - U2FsdGVk.jpg X1O9Z6e.jpg ECdjybF.jpg U2FsdGVajpg
How can I achieve this ?
var random_image_number = Math.floor((Math.random()*4)+1); // Picking a random number out of 4
Suppose random_image comes out to be 3. Now I need to display image number 3. If I had not hashed the image names, I would normally do this -
<img src="/images/" + random_image_number + ".jpg" />
But now I need to use the standard encryption algorithm again on the random number that I have generated, before I can display the image. (I keep stressing on "standard" since the same hashing algorithm has to work on JS side as well as in the bash script and generate the same result)
so i need some thing like this
var random_image_number = Math.floor((Math.random()*4)+1); // Picking a random number out of 4 var random_image_number_hashed = some_hashing_function(common_key, random_image_number) <img src="/images/" + random_image_number_hashed + ".jpg" />
Also, I am not sure how to write the bash script for renaming all the files using the hashing algorithm so any code regarding that will be really useful. Thank you.