# Encryption using ruby

**URL:** <https://www.ruby-forum.com/t/encryption-using-ruby/160937>\
**Category:** Ruby\
**Created:** [February 21, 2009, 4:58am UTC](https://www.ruby-forum.com/t/encryption-using-ruby/160937 "2009-02-21T04:58:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vetrivel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vetrivel](https://www.ruby-forum.com/u/vetrivel)\
**Post date:** [February 21, 2009, 4:58am UTC](https://www.ruby-forum.com/t/encryption-using-ruby/160937/1 "2009-02-21T04:58:46Z")

</div>

Herewith I have given code of perl encryption and decryption . If i give  
123 as  
no,the perl , encrypted the data and give it to us.How to do this in  
ruby.But If i give 123,the ruby should encrypt the data . The encrypted  
data should be same what perl has given.

use Crypt;  
print “enter the normal pin\n”;  
$entered\_pin = ;  
chomp ( $entered\_pin );  
my $EPin = Crypt::Encrypt ( $entered\_pin );  
print “Encrypted pin is : $EPin\n\n\n”;  
print “enter the encrypted pin\n”;  
$entered\_pin = ;  
chomp ( $entered\_pin );

chomp ( $entered\_pin );  
for ($i=0; $i\<=9999; $i++) {  
$pin = sprintf("%04d", $i);  
$ret = Crypt::Decrypt ($pin, $entered\_pin);  
if ($ret == 0) {  
print “The Pin is $pin\n”;  
}  
}

---

<div class="post-metadata">

**Author:** ![vetrivel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vetrivel](https://www.ruby-forum.com/u/vetrivel)\
**Post date:** [February 23, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/encryption-using-ruby/160937/2 "2009-02-23T14:26:33Z")

</div>

Please see my answer at [Perl Encrypt / Ruby Decrypt - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/178721) where  
exactly the same question was answered, but the OP didn’t bother to  
reply.

Here you have posted a bit more code. This shows that no decryption is  
taking place at all; rather, the Perl is trying all possible PINs until  
it stumbles on the correct one (AKA a “brute-force attack”)

Anyway, you just need to look at either the documentation for the perl  
Crypt::Encrypt function you are using to find out what sort of hashing  
it is doing, or probably easier, look at the Perl source and  
re-implement in Ruby.
