Jump to content


Photo

Perl to PHP


  • Please log in to reply
10 replies to this topic

#1 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 15 July 2006 - 10:06 PM

I need some help, i am trying to convert everything i have into PHP... currently i have it in JSP,Perl,PHP,.... and anything else you might think of, ive run into a small problem with crypt.... i was wondering if any one could help me.

the Perl version:
#!/usr/bin/perl

if( $#ARGV != 0 )
{
   print "usage: vcrypt password\n";
   exit 1;
}
my $salt = join '', ('.', '/', 0..9,'A'..'Z', 'a'..'z')[rand 64, rand 64];
print crypt($ARGV[0], $salt) ."\n";

how would i write the same thing in PHP??
Would i just have to use
crypt($password);
without a salt? or would i need to continue to specify that specific salt, and how would PHP accept that?

any help would be greatful.
-Branden

#2 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 15 July 2006 - 11:58 PM

Anyone?? anyone understand perl? if not i can explain what it needs to do in english, if you can help me put it in php
PLEASE help me.... Thank you.



#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 July 2006 - 12:19 AM

a description would help, yes.  i assume that $salt ends up being a string of random alphanum+/+. characters, 64 characters long?  what does crypt() then do with the salt?

#4 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 16 July 2006 - 04:06 AM

well in perl you can use the "crypt" function and similar to php you can "salt" the string to be crypted
basically telling the function what can be used (character wise) to crypt the password in this case
the ones mentioned previously.
i see that with the crypt function i can

crypt($password , $salt);

but it doesnt accept the same salt string, like perl does.

#5 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 July 2006 - 05:00 AM

assuming the salt is just a string containing all the characters you specified, you'd use:

$salt = implode('', array_merge(array('.'), array('/'), range(0, 9), range('a', 'z'), range('A', 'Z')));


#6 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 16 July 2006 - 05:11 AM

I don't know perl either but... php has a crypt function and if you don't supply a salt one will be generated for you. looks to me like perl is just creating a random salt???


:: gucci.com ::
:: blockbuster.com ::

--------------------

#7 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 16 July 2006 - 05:41 AM

join '', ('.', '/', 0..9,'A'..'Z', 'a'..'z')[rand 64, rand 64];

., /, the range 0-9, the range A-Z, and the range a-z are within a list () and make up 64 characters. The list is being sliced [] with two random indexes. For example, [0, 1] would give you '.' and '/'.

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#8 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 16 July 2006 - 06:15 AM

right i understand what the perl is doing, but i need to generate the same salt for the php crypt function.. so how would i do that?

crypt($password, ./[0-9A-Za-Z][rand 64,rand 64])

that doesnt work...so what am i doing wrong?

#9 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 16 July 2006 - 08:14 AM

This isn't exactly what it's doing (code for code), but same difference--getting two random values from the array.

<?php

	$array = array(
		'.',
		'/',
	);
	$array = array_merge(
		$array,
		range(0, 9),
		range('A', 'Z'),
		range('a', 'z')
	);

	shuffle($array);
	echo $salt = array_pop($array) . array_shift($array);

?>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#10 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 16 July 2006 - 10:33 PM

well i feel kinda stupid...

This doesnt work:
crypt($password, ./[0-9A-Za-Z][rand 64,rand 64])

This does:
crypt($password, "./[0-9A-Za-Z][rand 64,rand 64]")

all i missed were the freakin quotes, guess thats what happens when you spend too much time infront of the computer


#11 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 17 July 2006 - 07:25 PM

The string "./[0-9A-Za-Z][rand 64,rand 64]" is the salt though. The rand's are not actually being calculated, nor are the ranges taking effect.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users