# Function php =\> ruby

**URL:** <https://www.ruby-forum.com/t/function-php-ruby/85068>\
**Category:** Rails\
**Created:** [February 9, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/function-php-ruby/85068 "2007-02-09T20:07:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@Avo](https://www.ruby-forum.com/u/Avo)\
**Post date:** [February 9, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/function-php-ruby/85068/1 "2007-02-09T20:07:55Z")

</div>

Hi everyone 🙂

I’m starting in Ruby, and first I would like to translate a fonction php  
I made into a ruby one. In php it’s very slow due to the number of  
possibilities, the function is :

\<?php function boom($value) { $toto = "bbc4d9cb08ddbce591c28effcf6a6120005dc477"; $tabbb = array( "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); if(isset($value)){ for($i=0;$i\<=25;$i++){ for($j=0;$j\<=25;$j++){ for($k=0;$k\<=25;$k++){ for($l=0;$l\<=25;$l++){ for($m=0;$m\<=25;$m++){ for($n=0;$n\<=25;$n++){ for($o=0;$o\<=25;$o++){ for($p=0;$p\<=25;$p++){ $pass = $tabbb[$i].$tabbb[$j].$tabbb[$k].$tabbb[$l].$tabbb[$m].$tabbb[$n].$tabbb[$o].$tabbb[$p]; if( (substr\_replace( (sha1( strrev( md5($pass) ) )), "bb", 0, 2))==$toto ){alert($pass);} } } } } } } } } } } ?\>

Any idea? thx

---

<div class="post-metadata">

**Author:** ![Avo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@Avo](https://www.ruby-forum.com/u/Avo)\
**Post date:** [February 9, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/function-php-ruby/85068/2 "2007-02-09T20:19:20Z")

</div>

Avo wrote:

> I’m starting in Ruby, and first I would like to translate a fonction php  
> I made into a ruby one. In php it’s very slow due to the number of  
> possibilities, the function is :
> 
> \<?php function boom($value) { $toto = "bbc4d9cb08ddbce591c28effcf6a6120005dc477";

Get PhpUnit, and write unit tests for this function. Start with the  
simplest cases, such as ‘A’.

Then write simple unit tests in Ruby that match each input and output.  
“Grow” your Ruby function, by adding test cases that fail, then  
upgrading your function to pass. With a little perseverance, and a  
book on the Ruby language, you will have a rock-solid and bug-free  
implementation in no time.

Your design might come out the same, or different. Growing your  
function gives you many opportunities, while it is still small, to  
discover alternate patterns. The tests will make refactoring to any  
different pattern very easy.

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![Avo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@Avo](https://www.ruby-forum.com/u/Avo)\
**Post date:** [February 9, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/function-php-ruby/85068/3 "2007-02-09T20:22:38Z")

</div>

Avo wrote:

> Hi everyone 🙂
> 
> I’m starting in Ruby, and first I would like to translate a fonction php  
> I made into a ruby one. In php it’s very slow due to the number of  
> possibilities, the function is :

Hi Avo. How about

def boom  
puts “why not just ask them what their password is”  
end

It’s the pragmatic approach and it stands a greater chance of  
succeeding.

---

<div class="post-metadata">

**Author:** ![Avo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@Avo](https://www.ruby-forum.com/u/Avo)\
**Post date:** [February 9, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/function-php-ruby/85068/4 "2007-02-09T20:27:26Z")

</div>

Michael H. wrote:

> Avo wrote:
> 
> > Hi everyone 🙂
> > 
> > I’m starting in Ruby, and first I would like to translate a fonction php  
> > I made into a ruby one. In php it’s very slow due to the number of  
> > possibilities, the function is :
> 
> Hi Avo. How about
> 
> def boom  
> puts “why not just ask them what their password is”  
> end
> 
> It’s the pragmatic approach and it stands a greater chance of  
> succeeding.

lol, we can call it a “challenge” 🙂

---

<div class="post-metadata">

**Author:** ![Avo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@Avo](https://www.ruby-forum.com/u/Avo)\
**Post date:** [February 9, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/function-php-ruby/85068/5 "2007-02-09T22:15:41Z")

</div>

Michael H. wrote:

> puts “why not just ask them what their password is”  
> end
> 
> It’s the pragmatic approach and it stands a greater chance of  
> succeeding.

LOL!  
Much cleaner too.

–  
Chris M.  
Web D.

> **[Chriscodes.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=chriscodes.com)**
>
> Painless, quick delivery of your domain name. Fast and professional service.

---

<div class="post-metadata">

**Author:** ![Avo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@Avo](https://www.ruby-forum.com/u/Avo)\
**Post date:** [February 13, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/function-php-ruby/85068/6 "2007-02-13T22:10:15Z")

</div>

Chris M. wrote:

> Michael H. wrote:
> 
> > puts “why not just ask them what their password is”  
> > end
> > 
> > It’s the pragmatic approach and it stands a greater chance of  
> > succeeding.
> 
> LOL!  
> Much cleaner too.
> 
> –  
> Chris M.  
> Web D.  
> [http://chriscodes.com](http://chriscodes.com)

require ‘digest/md5’  
require ‘digest/sha1’

aFile = File.open “length7v.txt”, “r”

aFile.each do |line|  
md5 = Digest::MD5::hexdigest(line.chomp).reverse  
sha1 = “bb” + Digest::SHA1::hexdigest(md5)[2…39]

puts “Testing #{line}”

if sha1 == “bbc4d9cb08ddbce591c28effcf6a6120005dc477”  
puts “Found the pass : #{line}”  
system “pause”  
end

end

easy!!
