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

  • SEARCH
  • Home
  • 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 5942715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:17:34+00:00 2026-05-22T16:17:34+00:00

I came across this blog post which describes how they encrypt their ID’s. For

  • 0

I came across this blog post which describes how they encrypt their ID’s. For educational and entertainment purposes, I decided to try this out. I can’t quite get it, though.

As described in this blog post, I’m base 36 encoding the 3DES encrypted 64 bit padded value and keep getting the resulting string to be 25 characters long. How is it possible to get 13 characters, like the site claims, without using some stream cipher — the blog claims to use a 3DES block cipher.

Here’s the code I’m using:

require 'openssl'

SECRET_KEY = "secret"
ENCRYPTION_ALGO = "DES-EDE3-CBC"

def base36encode(s)
  s.unpack('H*')[0].to_i(16).to_s 36
end

def base36decode(s36)
  [s36.to_i(36).to_s(16)].pack 'H*'
end

def num_to_bits(n, bit_count=64)
  #Array.new(bit_count) { |i| (n)[i] }.reverse!
  sprintf('%064b', n).split("")
end

def bits_to_string(bits)
  [bits.join("")].pack("B*")
end

def num_to_binstring(n, bit_count=64)
  bits_to_string(num_to_bits(n, bit_count))
end

def binstring_to_num(str)
  #elements = str.unpack("N*")
  #(elements[0] << 32) | elements[1]
  #
  ans = 0
  str.each_byte do |i|
    ans = ans * 256 + i
  end

  ans
end

def encrypt(message, password)
  cipher = OpenSSL::Cipher::Cipher.new(ENCRYPTION_ALGO)
  cipher.encrypt
  cipher.pkcs5_keyivgen(password)
  ciphertext = cipher.update(message)
  ciphertext << cipher.final
end

def decrypt(message, password)
  cipher = OpenSSL::Cipher::Cipher.new(ENCRYPTION_ALGO)
  cipher.decrypt
  cipher.pkcs5_keyivgen(password)
  decryptedtext = cipher.update(message)
  decryptedtext << cipher.final
end

id = 12345678
puts "Encrypting: \"#{id}\""

num_string = num_to_binstring(id)
encrypted = encrypt(num_string, SECRET_KEY)
encoded = base36encode(encrypted).upcase
puts "Encrypted and encoded to: \"#{encoded}\" that's size is: #{encoded.length}\n"

decoded = base36decode(encoded.downcase)
decrypted = decrypt(decoded, SECRET_KEY)
string_num = binstring_to_num(decrypted)
puts "Decoded and decrypted to: \"#{string_num}\""

# ---- OUTPUT ---
# Encrypting: "12345678"
# Encrypted and encoded to: "49OMDVRHHMM24DVMODQU4X7JY" that's size is: 25
# Decoded and decrypted to: "12345678"
  • 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-05-22T16:17:34+00:00Added an answer on May 22, 2026 at 4:17 pm

    What size is the output of the encryption before you base36 encode? My guess is that your code is encrypting in CBC mode (given that your code mentions pkcs5) and you’re getting the IV and ciphertext out, a total of 16 bytes. I infer from the blog post that the author is using ECB mode, what you might think of as “raw” 3DES, which is usually wrong for most situations but seems plausible here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently came across this blog post which basically says that we should not
I recently came across this blog post Yet another post about gamma correction which
While browsing I came across this blog post about using the Wikipedia API from
It's easy! I just came across this blog post by Rudi Grobler that says
I came across this post on the MSMobiles.com blog that says the following, among
I was researching something and came across this blog post at buildstarted.com about model
I was configuring syntax highlighting for my blog when I came across this problem.
I came across this syntax which i have not seen before struct A {
I've recently came across a blog post about how you can use Photoshop PDF
I am reading this blog and came across following code RunAgain = Class.new(Exception) def

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.