Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:09:19+00:00 2026-06-08T00:09:19+00:00

I have a directory in my mac which has files with following names –

  • 0

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 ?

Furthur, I am writing some code in Nodejs (basically javascript), where I wish to pick a random image out of these four and display it, so I am using-

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" />

Please tell me what algorithm I could use. It doesn’t need to be much sophisticated, but must give the same result in the bash script as well as javascript side.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:09:22+00:00Added an answer on June 8, 2026 at 12:09 am

    Using openssl to rename the files and crypto.js on the javascript side, you should be able to use SHA1 to hash the filenames.

    The following bash loop will do the renames. Note that it assumes no space characters in filenames.

    for file in `/bin/ls *.jpg`; do
        hashedFileName=`echo -n ${file%.*} | openssl dgst -sha1 -hmac "myKey123"`;
        mv $file $hashedFileName.jpg;
    done
    

    Javascript-side will look something like the following for each image name:

    // hash filename "1.jpg":
    var hashedFileName = CryptoJS.HmacSHA1("1", "myKey123") + ".jpg";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have directory with > 1000 .html files, and would like to check all
I have a directory with around 50,000 .jpg images. Let's call this directory imageDir,
I have some files which need to be placed in a specific directory on
I have directory A with files matching directory B. Directory A may have other
I have directory structure like so: |-- ROOT |-- Project1 | |-- application |
Let's say I have Directory 1 and Directory 2, and each can have files
let's say i have directory paths looking like this: this/is/the/basedir/path/a/include this/is/the/basedir/path/b/include this/is/the/basedir/path/a this/is/the/basedir/path/b In
I have a directory OUTPUT where I have the output files from a Map
I have an application, which downloads a zip and unzips the files on my
I have install XCode Version 3.2, 4.2, and 5.0 and It has created Directory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.