Hi Every one,
I have a perl script which uses the following code to decode the username saved in a cookie. I want to parse that cookie in php for adding some more features in the application. The source application in perl but I don't know any thing about perl. Here is the code ... -
@table = (('A' .. 'Z'), ('a' .. 'z'), ('0' .. '9'), '+', '/', '|');
-
for ($_ = 0; $_ <= $#table; $_++) {
-
$decode_table[ord($table[$_])] = $_;
-
}
-
local $_ = $_[0];
-
s/./unpack('B6', chr($decode_table[ord($&)] << 2))/eg;
-
pack('B' . (int(length($_) / 8) * 8), $_);
-
Can any one help me to convert this code in PHP?
Thanks in advance
9 4980 numberwhun 3,509
Recognized Expert Moderator Specialist
Sure, if this were the PHP forum . Unfortunately, it is not and I know that I do not know any PHP. What I can do though, is move this to the PHP forum where hopefully they can help you.
Please know that you might have to specify what your requirements are for the script to do and also write code (these are learning forums).
On the other hand, if you are looking for someone to write this for you, then you can certainly post this to the Jobs forum and offer to pay someone. The choice is up to you.
Regards,
Jeff
pbmods 5,821
Recognized Expert Expert
Heya, aliusman.
I'm no Perl guru, but I dabble from time to time in the dark arts. Let's see if we can run through this and generate a suitable translation.
And if I happen to get anything wrong, perhaps numberwhun would be wiling to step in and assist... *AHEM*.
Anyway. - @table = (('A' .. 'Z'), ('a' .. 'z'), ('0' .. '9'), '+', '/', '|');
This line creates a big 'ol table with all the letters and numbers, and a few symbols to boot. - for ($_ = 0; $_ <= $#table; $_++) {
-
$decode_table[ord($table[$_])] = $_;
-
}
Now we're looping through the table array that we created and generating a new hash called #decode_table (in Perl, hashes start with the '#' character, but you reference individual elements in the hash using '$'). The keys of this table are the ordinal values of @table and the values start with 0 and increase by 1 each time.
This creates a local variable $_ and sets it equal to the first index in the special $_ variable (rough equivalent in PHP is probably $_GET or $_COOKIE). -
s/./unpack('B6', chr($decode_table[ord($&)] << 2))/eg;
-
pack('B' . (int(length($_) / 8) * 8), $_);
Got no idea here. Perhaps numberwhun could be of some assistance as to the purpose of these lines. *AHEM*
Markus 6,050
Recognized Expert Expert
Sounds like you need some cough medicine, Josh.
pbmods 5,821
Recognized Expert Expert
Ooh, cherry-flavored.
Alrightey. After further consultation with our Perl forum leader, we (well, he) determined that the code you provided is not adequate to determine what's going on.
He checked it out, and here are the errors it generates: - Useless use of pack in void context at C:/coding/Eclipse_Workspace/Perl_Testing_Area/test4.pl line 15.
-
Use of uninitialized value $_ in substitution (s///) at C:/coding/Eclipse_Workspace/Perl_Testing_Area/test4.pl line 13.
-
Use of uninitialized value $_ in length at C:/coding/Eclipse_Workspace/Perl_Testing_Area/test4.pl line 15.
-
Use of uninitialized value $_ in pack at C:/coding/Eclipse_Workspace/Perl_Testing_Area/test4.pl line 15.
If you can, please post the rest of the code. If that's all you have, we'll need some more info on where the code came from.
... -
s/./unpack('B6', chr($decode_table[ord($&)] << 2))/eg;
-
pack('B' . (int(length($_) / 8) * 8), $_);
Got no idea here. Perhaps numberwhun could be of some assistance as to the purpose of these lines. *AHEM*
That's probably intended to be the encoding/decoding part.
The pack converts a string into some machine level representation and the unpack does the opposite. The OP might just want to explain what their algorithm is for the decode and then we could suggest the php equivalence of that.
pbmods 5,821
Recognized Expert Expert
Unfortunately, PHP's pack() function takes a slightly different syntax than Perl's ( http://php.net/pack), so I'm afraid that this is beyond my ken.
I will go ahead and move this thread back to the Perl forum so that the OP might be able to get a better idea of what's going on. Once we have that, then we can tackle how to translate it.
KevinADC 4,059
Recognized Expert Specialist
it would be nice to see what the value of $_ is from this line of the code:
local $_ = $_[0];
without knowing what the input is trying to figure out the correct output is going to be useless. But I have a feeling this thread has been abandoned anyway.
$decoded_string = base64_decode($ thestring);
echo $decoded_string ;
;)
numberwhun 3,509
Recognized Expert Moderator Specialist @slattman
This thread has not been posted to for about 8 months. It is quite possible that the OP has either forgotten about this issue, solved i t or moved on.
While it is commendable to provide answers, please keep these things in mind in the future.
Regards,
Jeff
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Klaus Neuner |
last post by:
Hello,
I need a function that converts a list into a set of regexes. Like so:
string_list =
print string_list2regexes(string_list)
This should return something like:
|
by: steeve.nadeau |
last post by:
Hi
I search algorithme to convert XY into Latitude/longitude to use
customer data with GPS...
thk in advance.
|
by: Manzoorul Hassan |
last post by:
I need to convert a date / time to NTP Timestamp, in HEX no less, and
was wondering if there might be a module for it.
Any ideas? I have been searching for NTP Timestamp under Perl but have
not found much - yet.
- manzoor
|
by: gilad |
last post by:
Hi, I have just released the initial beta of a C# project called
'aumplib'. aumplib is a C# namespace which is made up of a set of
classes that interface several prominent open source audio conversion
projects via DLL and P/Invoke: LAME (MP3 encoding), libsndfile (non-MP3
audio conversion), and libmad (MP3 decoding; through madlldlib).
Essentially, aumplib provides an OO wrapper to these libraries.
I am interested in any comments anyone...
|
by: =?ISO-8859-7?B?1/H189zt6Ocgwfrt4eve?= |
last post by:
How can I convert a perl script to Python?
Thank you!
| |
by: parajaganesh |
last post by:
I am a new man to Perl. Anybody can help me to convert a perl program into .com format.
|
by: poolboi |
last post by:
hi guys,
i've read a lot of thread of converting excel data into CSV files.
however, i need a perl script to convert CSV file into excel file now, if required modules is needed, it would be preferable if win32::OLE is used..
currently what i know is when i change my extension as .csv file mannually, it get changed to an excel file through Microsoft Excel CSV file
so if i were to use a perl script and convert
the perl script has to...
|
by: pointzero |
last post by:
Can someone help me to convert the following perl code into php? Leave the Net::DNS, Net::DNS::Resolver, search functions as is. I can replace them with PEAR Net_DNS module.
use Net::DNS;
sub ablookup {
my ($domain) = @_;
my ($res, $query, @r);
$res = new Net::DNS::Resolver;
while(1) {
|
by: brainbox |
last post by:
I have 2 questions:
1.When I read the number using (\S+) its getting stored as 2.08E13.
Code I used:
if ($line=~/4_begindt_(\S+)/) {
print "$1\n" }
# $1=2.08E13; instead $1 should contain 20080928014155
How to read and store a 15digit number in perl?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |