473,408 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Perl to PHP conversion

2
Hello,
I need help in converting following perl script functions into php, can anyone pls?

sub Encrypt {
my ($source,$key,$pub_key) = @_;
my ($cr,$index,$char,$key_char,$enc_string,$encode,$f irst,
$second,$let1,$let2,$encrypted,$escapes) = '';
$source = &rot13($source);
$cr = '·¨*';
$source =~ s/[\n\f]//g;
$source =~ s/[\r]/$cr/g;
while ( length($key) < length($source) ) { $key .= $key }
$key=substr($key,0,length($source));
while ($index < length($source)) {
$char = substr($source,$index,1);
$key_char = substr($key,$index,1);
$enc_string .= chr(ord($char) ^ ord($key_char));
$index++;
}
for (0..255) { $escapes{chr($_)} = sprintf("%2x", $_); }
$index=0;
while ($index < length($enc_string)) {
$char = substr($enc_string,$index,1);
$encode = $escapes{$char};
$first = substr($encode,0,1);
$second = substr($encode,1,1);
$let1=substr($pub_key, hex($first),1);
$let2=substr($pub_key, hex($second),1);
$encrypted .= "$let1$let2";
$index++;
}
return $encrypted;
}
sub rot13{
my $source = shift (@_);
$source =~ tr /[a-m][n-z]/[n-z][a-m]/;
$source =~ tr /[A-M][N-Z]/[N-Z][A-M]/;
$source = reverse($source);
return $source;
}
Mar 1 '07 #1
1 885
Motoma
3,237 Expert 2GB
Perhaps you could tell us what this method of encryption is called? Or explain the way the technique works?
It would be easier to rewrite the method than convert code line by line.
Mar 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Edward WIJAYA | last post by:
Hi, I am new to Python, and I like to learn more about it. Since I am used to Perl before, I would like to know what is Python equivalent of Perl code below: $filename = $ARGV;
11
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # the "filter" function can be used to © # reduce a list such that unwanted © # elements are removed. © # example: © © def even(n): return n % 2 == 0...
0
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # once a module is loaded © # import mymodule © # one can find all the names it © # export with dir() © © import sys © print dir(sys)
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
2
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # in Python, one can define a boxed set © # of data and functions, which are © # traditionally known as "class". © © # in the following, we define a...
3
by: Chris Pruett | last post by:
An odd (to me) behavior I was hoping someone could explain. Take the simple command: perl -e 'print 0xCEC5 + 0xFFFFE253 & 0xFFFF' I tried this on a number of computers. Most give 0xFFFF, ...
1
by: Dark | last post by:
Im trying to insert a clob into the database and I get the following error. DBD::DB2::st execute failed: SQL0804N The application program input parameters for the current request are not...
3
by: mdaetwyler | last post by:
Hi all I am trying to call a DB/2 v8.2 stored procedure from Perl DBI and am getting an error message telling me, that the routine could not be found in the library path. SQL0444N Routine...
2
by: jeffrey.bigham | last post by:
Hello, I'm writing a program that needs to read input line by line and analyze each, and it needs to be as efficient as possible. I wrote the following sample program that works, but is 10...
12
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.