Sei sulla pagina 1di 27

1.How to Connect to mysql database & retrieve data in perl ?

Ans :
# Use of MySQL
##############

use DBI;
#use DBD::mysql;

# Set the variables for the Database Connection
my host ! "#btest"; # your #atabase server$ can be localhost
my #atabase ! "Lo%"; # connectin% #atabase
my table ! "Do&nloa#e#'iles" # table &ithin the #atabase
my #buser ! "(rivate"; # #atabase lo%in useri#
my #b(ass ! "(rivate"; # #atabase lo%in (ass&or#

#bh ! DBI)*connect+"DBI:mysql:#atabase!#atabase;host!host"$#buser$#b(ass, -- #ie
".nDB connection error/.n";
sth ! #bh)*(re(are+"select 0 from table &here ID ! 122331",;
sth)*e4ecute+,;
&hile +5#ata ! sth)*fetchro&6array+,, 7
(rintf+"ID: 8s.n"$#ata9:;,;
(rintf+"Date: 8s.n"$#ata9<;,;
(rintf+"=ime: 8s.n"$#ata9>;,;
(rintf+"Status: 8s.n"$#ata9?;,;
(rintf+"@ash: 8s.n"$#ata92;,;
(rintf+"Com(any: 8s.n"$#ata93;,;
(rintf+"'ileAame: 8s.n"$#ata9B;,;
(rintf+"'ileSiCe: 8s.n"$#ata9D;,;
(rintf+"Lo% Messa%e: 8s.n"$#ata9E;,;
F

# Gequire# is DBI H DBD::mysql$ both of these are available from CIanJ
2. Validating postal codes in perl ?
Ans :
sub vali#6(ostalco#e+,
7
my co#e ! shift+56,;
if+/+co#e !K LM+.s,0+9a)C;+.s,0.#+.s,0,7?F+.s,0Li,,
7
return+"=he Iostal Co#e: co#e is invali#/",;
F
return+"oN/",;
F
3. oogle !in" #$tractor in perl ?
Ans :
#IGOBLPM <: QP= RLL =@P LIASS IA R QOOQLP SPRGC@ IRQP

#/LusrLlocalLbinL(erl
#use LTI::Sim(le;
require LTI::UserR%ent;
#use @==I::Gequest;
#use @==I::Ges(onse;
#use @=ML::LinNP4tor;
my ua ! LTI::UserR%ent)*ne&;
ua)*timeout+<:,;
ua)*env6(ro4y;
ua)*a%ent+ 1'irefo4L>J:J:J<1 ,;
#for %ettin% the linNs in the subsequent (a%es
#5url!+1htt(:LL&&&J%oo%leJcoJinLsearchUhl!enHcliesite:htt(:LLa%(&ebJ&or#(ressJcomnt!firefo4)
aHrls!comJubuntu8?Ren)US
8?RofficialHhs!sIIHq!RVayWQeor%eWHbtnQ!SearchHmeta!1$1htt(:LL&&&J%oo%leJcoJinLsearchU
q!RVayWQeor%eHhl!enHclient!firefo4)aHrls!comJubuntu:en)
US:officialHstart!<:Hsa!A1$1htt(:LL&&&J%oo%leJcoJinLsearchU
q!RVayWQeor%eHhl!enHclient!firefo4)aHrls!comJubuntu:en)US:officialHstart!>:Hsa!A1,
url ! 1htt(:LL&&&J%oo%leJcoJinLsearchUhl!enHclient!firefo4)aHrls!comJubuntu8?Ren)US
8?RofficialHhs!sIIHq!RVayWQeor%eWHbtnQ!SearchHmeta!1;
my res(onse ! ua)*%et+ url ,;
start!1Xh> class!r*Xa href!."1;
en#! 1" class!l*1;
content!res(onse)*content+,;
&hile +content !K mLstart+J0U,en#L%,
#Or use this &ithout the variables
#&hile +content !K mLXh> class!r*Xa href!."+J0U,." class!l*L% , # U for shortest match an# L% for
all the occurencesJ
7(rint +"<.n",;
F
#(rint res(onse)*content;
%. !ist all e$ec&table 'iles in yo&r ()A*H ?
Ans :
#/LusrLbinL(erl
#(ur(ose: to #is(lay all the e4ecutable files in all the #irectories in your IR=@
#%et the IR=@ environmental variable that you &oul# have in bash$
#here I assi%n it to a variable in (erl of the same name$ IR=@
IR=@!Yecho .IR=@Y;
#no& store an array of #irectory names that are in IR=@$ the :
#character se(arates each name
5a6#irectory6names ! s(lit+L:L$ IR=@,;
#foun# this follo&in% comman# to list only e4ecutable files in a #irectory at this &eb a##ress:
#htt(:LL%rou(sJ%oo%leJcomL%rou(LaltJosJlinu4Lbro&se6threa#Lthrea#LB3cZfDDB:ZE>DbeBLc>>2Z<Ec
3?3b<#Ee8>?c>>2Z<Ec3?3b<#Ee
#fin# L#ir )(erm W<<< )ma4#e(th < )ty(e f
siCe ! 5a6#irectory6names;
# iterate over array
for +i!:; iXsiCe; iWW,
7
(rint Yfin# La6#irectory6names9i; )(erm W<<< )ma4#e(th < )ty(e fY;
F
#an# since I #on1t have the current #irectory in my (ath$ I1ll (rint e4ecutable files in it se(arately
(rint Yfin# JL )(erm W<<< )ma4#e(th < )ty(e fY;
+. ,eversing a -tring in perl ?
Ans :
#/LusrLbinL(erl )&
use strict;
(rint "Pnter &or# to reverse: ";
chom(+my &or# ! XS=DIA*,;
my reverse#Tor# ! scalar reverse &or#;
(rint "Ori%inal Tor#: &or#.n";
(rint "Geverse# Tor#: reverse#Tor#.n";
.. /rite to a 'ile in perl ?
Ans :
#/LusrLlocalLbinL(erl
# Tritten by #>(encil <:L:ZL>::D
# Construct the current #ateJ
+Secon#$ Minute$ @our$ Day$ Month$ [ear, ! localtime+time,;
Month ! Month W <; # Increment month by <J
Lon%[ear ! [ear W <Z::; # Set Lon%[earJ
if+[ear *! <::, 7
[ear ! [ear ) <::;
F
Day ! s(rintf+"8:>#"$Day,;
Month ! s(rintf+"8:>#"$Month,;
[ear ! s(rintf+"8:>#"$[ear,;
@our ! s(rintf+"8:>#"$@our,;
Minute ! s(rintf+"8:>#"$Minute,;
Secon# ! s(rintf+"8:>#"$Secon#,;
currentDate ! [ear J Month J Day;
archiveDate ! Lon%[ear J Month J Day;
current=ime ! "@ourMinuteSecon#";
o(en +M['ILP$ 1**#ataJt4t1,;
(rint M['ILP "currentDate current=ime.n.n";
#ir!"JJLlo%";
o(en#ir D@$ #ir or #ie "Cannot o(en #ir:";
&hile+file!rea##ir D@, 7
if+file !K L+.J,L, 7
name!file;
F
else 7
name!file;
(rint M['ILP "Do&nloa#e# "JnameJ".n";
F
F
close +M['ILP,;
0. )rints o&t prime n&mbers and t1eir seq&ence n&mber in perl ?
Ans :
#/LusrLbinL(erl
use &arnin%s;
to ! RGQ\9:;;
my 5(rimes ! +>,;
my trythis ! >;
count ! <;
&hile +count X to, 7
#checNs if (ossible (rime can be #ivi#e#
APT: foreach (rime +5(rimes, 7
if +/+trythis 8 (rime,,
7 not(rime ! <;
trythisWW;
ne4t;
F
F
#if number is fla%%e# as "not(rime"$ starts a%ain
if + not(rime !! < ,
7 not(rime ! :;F
else 7
##oes this if number is not marNe# as "not(rime"
#(ushes the (rime to an array
(ush 5(rimes$ trythis;
#a##s one to count
countWW;
#(rints (rime an# sequence number
(rint "trythis";
(rint " ) .#count.n";
trythisWW;
#ne&
%oto APT;
F
F
2. ,ead a 'ile3 display t1e res&lts ?
Ans :
#/LusrLlocalLbinL(erl
# Tritten by #>(encil <:L:ZL>::D
#ata6file!"#ataJt4t";
i!<;
o(en+M['ILP$ #ata6file, -- #ie+"Coul# not o(en lo% file/",;
5ra&6#ata!XM['ILP*;
foreach line +5ra&6#ata, 7
cho(+line,;
(rint "i, line.n";
iWW;
F
close+M['ILP,;
4. -imple #q&ation to /ords Conversion ?
Ans :
#/C:.(erl.bin.(erl
if+5RGQ\9:; eq "",
7
(rint +".n",;
(rint +"synta4: (erl equationJ(l 1equation1 .n",;
(rint +"1equation1 must be in form letterLnumberLo(erator letterLnumberLo(erator .n",;
(rint +"e% for 24 W y synta4 &oul# be (erl equationJ(l 2 4 W y .n",;
F
else
7
(rint +"5RGQ\ .n",;
(rint +"s(ecify a file to save as: ",;
filename ! XS=DIA*;
COUA= ! :;
o(en+OU='ILP$ "*fileJ(l",;
(rint OU='ILP +1#/C:.(erl.bin.(erl1,;
(rint OU='ILP +".n",;
(rint OU='ILP +1# 1,;
(rint OU='ILP +"file Create# by equationJ(l automatic (erl scri(t %enerator .n.n.n",;

breaN ! :;
varcount ! :;
&hile +5RGQ\9COUA=; ne "" HH breaN /! <,
7
if +5RGQ\9COUA=; !K L9a)C R)];L,
7
(rint +"letter.n",;
(rint OU='ILP +1(rint +"1,;
(rint OU='ILP +"5RGQ\9COUA=; in(ut:",;
(rint OU='ILP +1 ",;1,;
(rint OU='ILP +".n",;
(rint OU='ILP +11,;
(rint OU='ILP +"5RGQ\9COUA=; ! ",;
(rint OU='ILP +1XS=DIA*;1,;
(rint OU='ILP +".n",;
varcountWW;

F
elsif+ 5RGQ\9COUA=; !K L.#L,
7
(rint +"#i%it.n",;
F
elsif + 5RGQ\9COUA=; eq "W" -- 5RGQ\9COUA=; eq ")" -- 5RGQ\9COUA=; eq "0" --
5RGQ\9COUA=; eq "8" -- 5RGQ\9COUA=; eq "L" -- 5RGQ\9COUA=; eq "M",
7
if +COUA= !!:,
7
breaN ! <;
(rint +"error/ math o(erator can not be%in equation.n",;
F

else7F
(rint +"math o(erator.n",;
F


else
7
(rint +"error.n",;
F
COUA=WW;
F
(rint OU='ILP +1result ! 1,;
COUA= ! :;
&hile +5RGQ\9COUA=; ne "" HH breaN /! <,
7
if +5RGQ\9COUA=; !K L9a)C R)];L,
7
(rint OU='ILP +11,;
(rint OU='ILP +"5RGQ\9COUA=; ",;
F
elsif +5RGQ\9COUA=; eq "W",
7
(rint OU='ILP +" W ",;
F
elsif +5RGQ\9COUA=; eq "0",
7
(rint OU='ILP +" 0 ",;
F

elsif +5RGQ\9COUA=; eq ")",
7
(rint OU='ILP +" ) ",;
F
elsif +5RGQ\9COUA=; eq "L",
7
(rint OU='ILP +1 L 1,;
F

elsif+ 5RGQ\9COUA=; !K L.#L,
7
(rint OU='ILP +"5RGQ\9COUA=; ",;
F

elsif +5RGQ\9COUA=; eq "+" ,
7
(rint OU='ILP +1 + 1,;
F
elsif +5RGQ\9COUA=; eq "," ,
7
(rint OU='ILP +1 , 1,;
F

elsif +5RGQ\9COUA=; eq "M",
7
(rint OU='ILP +1 00 1,;
F

elsif +5RGQ\9COUA=; eq "8",
7
(rint OU='ILP +1 8 1,;
F

else 7F
COUA=WW;
F
(rint OU='ILP +"; .n",;
(rint OU='ILP +1(rint +"result is result .n",;1,;
(rint OU='ILP +".n",;
F
15. )alindrome C1ec"ing ?
Ans :
sub (alin#rome6checN 7
my ( ! shift;
if+( eq reverse (, 7
return <;
F else 7
return :;
F
F
11. -imple 6egative 6&mber C1ec" ?
Ans : Iass the number you &ant checNe# into the subroutine$ an# it &ill return a < if the number
is ne%ative$ an# a : if it is (ositiveJ
sub checNAe%ative 7
my+checN\alue, ! 56;
if+abs+checN\alue, /! checN\alue, 7
# in this case$ the value is ne%ative; return <
return <;
F else 7
# number is (ositive; return :
return :;
F
F
12. -&bro&tine to ,emove w1ite space 'rom t1e start and end o' a string.
Ans:
sub trim&hites(ace 7
my +strin%, ! shift;
strin% !K sLM.sWLL;
strin% !K sL.sWLL;
return strin%; ## =hanNs SevinRDC
F
13. 7ser 8) !ogger in perl ?
Ans : Saves the II of the User as &ell as his localtime &hen a (a%e is accesse#J OGIQIARL
RU=@OG UASAOTAJ
#/C:.Ierl.bin.(erlJe4e
#Lo%%er
t ! localtime;
i( ! "PA\71GPMO=P6RDDG1F";
###########################
o(en+IA$ "lo%%erJ%if",;

binmo#e+IA,;
rea#+IA$ ima%e$ )s "lo%%erJ%if",;
close+IA,;
###########################
binmo#e+S=DOU=,;
(rint "Content)ty(e: ima%eL%if.n";
(rint ".n";
(rint ima%e;
###########################
o(en+OU=$ "**lo%Jhtm",; #O(ens lo%Jhtm for Out(ut of II R##ress
(rint OU= "Rccess from: i( at tX(*.n"; #Out(uts the I( a##ress to lo%JhtmJ
close+OU=,;
1%. -ingle 9irectory :)3 !in" !ister ?
Ans : =his co#e lists all the MI?1s as linNs in @=ML formatJ OGIQIARL RU=@OG IS UASAOTAJ
#/c:.a(achefrien#s.4am((.(erl.bin.(erlJe4e
#X/)) the only thin% you have to chan%e is the (ath to the m(? files ))*
#X/)) this &ill only list one #irectory not sub#irctories ))*
#X/)) maNe sure to use for&ar# slashes &hen e#itin% (ath +P4am(le: (ath!"c:L&inntLm(?s", ))*
#X/)) also this scri(t &on1t &orN if you use a hy(hen in the (ath +P4am(le: TOA1= TOGS !!*
(ath!"c:L&inntLm(?1s", ))*
(ath!"c:L&innt";
o(en#ir+DIG$ "(ath",;
5m(?!%re(+ L.Jm(?L$ rea##ir+DIG, ,;
5m(?!sort+5m(?,;
close#ir+DIG,;
(rint "Content)ty(e: te4tLhtml.n.n";
(rint "Xhtml*.n";
(rint "Xhea#*.n";
(rint "Xtitle*List of MI?1sXLtitle*.n";
(rint "XLhea#*.n";
(rint "Xbo#y linN!1#??::CC1 vlinN!1#??::CC1 alinN!1#??::CC1*.n";
(rint "Xfont face!1%eor%ia1 siCe!1?1*Xb*(athXLb*XLfont*.n";
(rint "Xfont face!1%eor%ia1siCe!1>1*Xul*.n";
foreach m(?+5m(?,
7(rint "Xli*Xa href!1(athLm(?1*m(?XLa*XLli*";F
(rint "XLul*XLfont*.n";
(rint "XLbo#y*.n";
(rint "XLhtml*.n";
1+. ,andom )assword enerator ?
Ans : R sni((et that can be use# in any (erl (ro%ram to %enerate a ran#om (ass&or#J
# Call the ran#6(ass+, subroutine from
# any&here in a (erl scri(t to %enerate
# a ran#om (ass&or#J
my (ass&or# ! ran#6(ass+,;
# no& #o somethin% &ith (ass&or# :,
# Ilace this subroutine any&here in a (erl
# scri(t to (ass bacN a (ass&or# for use
# as nee#e#J

sub ran#6(ass 7
# Rn array of characters use# to maNe the (ass&or#sJ
# Lo&er)case 1L1 an# the number one 1<1 as &ell a
# lo&er)case 1O1 an# the number Cero 1:1 are omitte#
# to avoi# confusion bet&een themJ U((er)case al(ha
# characters coul# be a##e# if mi4e#)case (ass&or#s
# are #esire#J
my 5chars ! +1a1JJ1N1$1m1$1n1$1(1JJ1C1$1>1JJ1Z1,;
# =he number of characters to use in (ass&or#s
my len%th ! <>;
# InitialiCe an em(ty strin%J
my (ass&or# ! 11;
# R loo( to %et ran#om characters from the array
# an# concatenate them into a (ass&or#J
for +<JJlen%th, 7
(ass&or# J! chars9int ran# 5chars;;
F
#return the (ass&or# bacNJ
return (ass&or#;
F
1.. ,andom 8ns&lts ?
Ans : (lace in your c%i)bin #irectory H %ive the require# (ermsJ
#/LusrLbinL(erl
# Tritten by #>(encil
# =his scri(t can be seen live at htt(:LL&&&JaNronc#nrJcomLc%i)binLinsultJc%i
use CQI;
co ! ne& CQI;
o(en+COUA=$"XcounterJ#at", or #ie "Coul# not o(en counter #ata file";
count ! XCOUA=*;
close COUA=;
countWW;
o(en+COUA=$"*counterJ#at",;
(rint COUA= count;
close COUA=;
0enter!.:;
ver ! Y(erl )v - %re( ?EB - cut )#" " )f2Y;
line< ! "Tritten by RNron Com(uter Desi%n H Ge(air:Xbr*";
line> ! "&&&JaNronc#nrJcom <>L<<L>::BXbr*";
(rint
co)*hea#erJ
co)*start6html+
)title!*1Insult Master/1$
)author!*1number>(encil1$
)BQCOLOG!*1&hite1$
,$
co)*center+co)*h<+1Insult Master/1,,$
co)*($
co)*center+"Xtable bor#er!> bor#ercolor!blacN*Xtr*Xt#*Brou%ht to you by : IPGL
"$ ver$ "XLt#*XLtr*XLtable*",$
co)*($
co)*center+"Ilease Niss My 7HinsultF Rss/",$
co)*($
co)*center+co)*h?+"[ou are insult #"$ count,,$
co)*($
co)*center+line<,$
co)*center+line>,$
co)*($
co)*en#6html;
#Sub insult
sub insult 7
5insult ! +
"Mother 'ucNin%"$ "Qo#)Damne#"$
"Butt 'ucNin%"$ "Aobo#y"$
"^erN"$ "Meat)Ta#"$
,;
r ! ran# B;
ms% ! insult9r;;
return "ms%"
F;
10.:d+
Ans : Use of m#3 to create <>E)bit hash value
# Use of m#3
# )#>(encil) Tritten for XDreamInCo#eJnet L* ) <:L<>L>::D
############
use Di%est::MD3 q&+m#3 m#36he4 m#36baseB2,;
VunN!m#36he4+"=he quicN bro&n fo4 Vum(s over the laCy #o%",;
(rintf+"8s.n.n"$VunN,;
# Aote:Aone of these functions are e4(orte# by #efaultJ
# =his means$ you can1t Vust use the Di%est::MD3 mo#ule on to( of your co#e an# then
# call the m#3 functionJ =his &ill result in an error sayin% m#3 function not foun#J
# =o avoi# this$ &e loa#e# the mo#ule &ith use Di%est::MD3 q&+m#3 m#36he4 m#36baseB2,;
# results can be com(are# &ith 9url;htt(:LLenJ&iNi(e#iaJor%L&iNiLMD39Lurl;
12.:9+ :/it1 'iles ?
Ans : R## this sni((et to your (erl scri(t$ H you can fee# files via comman# lineJ It &ill %ive the
m#3 results on each file (asse# inJ
#
# Use of m#3 : &ith files
#
# )#>(encil) Tritten for XDreamInCo#eJnet L* ) <:L<3L>::D
#
################
use Di%est::MD3 q&+m#3 m#36he4 m#36baseB2,;
use IO::'ile;
my chN ! Di%est::MD3)*ne&+,;
foreach my file +5RGQ\, 7
chN)*a##file+IO::'ile)*ne&+file,,;
(rint "file : "$chN)*he4#i%est$".n";
F
14. et t1e n&mber o' days in a given mont1 ?
Ans : =his sni((et &ill allo& you to retrieve the number of #ays in a (articular monthJ
use =ime::DaysInMonth;
## Te retrieve the current #ay$ month$ an# year offset
my +un#ef$un#ef$un#ef$#ay$month$year, ! localtime+,;
## Te then a#Vust our year value to maNe sure &e1re in the ri%ht year
yearW!<Z::;
## Rn# our month value$ because #ays6in taNes months startin% &ith <$ an# the return value from
localtime+, is :JJ<<J
monthW!<;
my #ays ! #ays6in+year$month,;
## #ays &ill no& have the number of #ays in this month insi#e itJ
25. eneric :en& wit1 s&b ?
Ans :
Use the sub function to create a loo(in% menuJ
#/LusrLbinL(erl
# Tritten by #>(encil for XL#ream)in)co#e* DL?<L>::D
# Descri(tion: Qeneric Menu &ith sub
(rint ".n!!!!!!! Rutomate# menu";
(rint ".nTritten by #>(encil for XL#ream)in)co#e* DL?<L>::D";
(rint ".n!!!!!!!.n.n.n";
ch!<;
if+ch X <:,7 menu+ch,; F
else 7 (rint "Don1t #o it/.n"; F
sub menu 7
ch!:; # &hatever it &as$ &e #on1t care/
#o 7
for+i!:;iX?3;iWW, 7
(rint+"0",;
F
(rint ".n <J, Item <";
(rint ".n >J, Item >";
(rint ".n ?J, Item ?";
(rint ".n 2J, Item 2";
(rint ".n 3J, Item 3";
(rint ".n BJ, e4it.n";
for+i!:;iX?3;iWW, 7
(rint+"0",;
F
(rint ".n.nIlease enter your choice: ";
ch!XS=DIA*;
cho(+ch,;
checN+ch,;
F &hile ch!:;
F
sub checN 7
if+ch !! 1B1, 7
(rint ".n.nP4itin%";
e4it+:,;
F
if+ch !! 1<1, 7
(rint ".n.nLaunchin% Item <.n";
F
if+ch !! 1>1, 7
(rint ".n.nLaunchin% Item >.n";
F
if+ch !! 1?1, 7
(rint ".n.nLaunchin% Item ?.n";
F
if+ch !! 121, 7
(rint ".n.nLaunchin% Item 2.n";
F
if+ch !! 131, 7
(rint ".n.nLaunchin% Item 3.n";
F
menu+ch,;
F
21. ;ile -i<e 7sing ;ile :et1od ?
Ans : =his sni((et uses 'ile::stat to retrieve the siCe of the fileJ
#/LusrLbinL(erl
use strict;
use &arnin%s;
use 'ile::stat;
my (ath ! "J";
my file ! "testJt4t";
my filesiCe ! stat+(athJ"L"Jfile,)*siCe;
(rint "SiCe: filesiCe.n";
22.;ile -i<e
Ans : Stan#ar# &ay to retrieve the siCe of a fileJ
#/LusrLbinL(erl
use strict;
use &arnin%s;
my filesiCe ! )s "fileJt4t";
(rint "SiCe: filesiCe.n";
23.;ile -earc1
Ans : Irint all the Ierl Iro%rams in the Directory
#/LusrLbinL(erl
# Tritten by #>(encil for Dream In Co#e :<L:>L>::E
os6! MO;
# @ere you coul# (erform any testin% o(erations on the result
# 'or e4am(le :
if+os6!K"MSTin?>", 7
(rint "Usin% Microsoft Tin#o&s:.n";
e4it :;
F
if+os6!K"freebs#", 7
(rint "Usin% 'reeBSD:.n";
e4it :;
F
if+os6!K"cy%&in", 7
(rint "Gunnin% Cy%&in:.n";
e4it :;
F
(rint "os6.n";
23. ;ile C1ec"s ?
Ans : =his scri(t runs tests on all files in the current #irectory +sNi((in% J H JJ, H %ives some
results on those testsJ
#/LusrLbinL(erl
# Tritten by #>(encil DL>3L>::D
i!:; #inc counter
#ir!"J"; #current #irectory
o(en#ir D@$ #ir or #ie "Cannot o(en #ir:";
#foreach file +rea##ir D@, 7
&hile+file!rea##ir D@, 7
if+file !K L+.J,L, 7
name!file;
F
else 7
name!file;
(rint ".n=estin% fla%s for name";
(rint ".n!!!!!!!!! Iossible 'ile =y(e =ests ";
if + file !K L+.J(l,L , 7
(rint ".n is a (erl scri(t";
F
if + file !K L+.Jc,L , 7
(rint ".n is c co#e";
F
if + file !K L+.Jc((,L , 7
(rint ".n is c(( co#e";
F
if + file !K L+.J(h(,L , 7
(rint ".n is (h( co#e";
F
if + file !K L+.Jsh,L , 7
(rint ".n is a shell scri(t";
F
(rint ".n!!!!!!!!! Pffective User ID =ests ";
(rint ".n is rea#able" if+ )r name,;
(rint ".n is &ritable" if+ )& name,;
(rint ".n is e4ecutable" if+ )4 name,;
(rint ".n is o&ne# " if+ )o name,;
(rint ".n!!!!!!!!! Geal User ID =ests ";
(rint ".n is rea#able" if+ )G name,;
(rint ".n is &ritable" if+ )T name,;
(rint ".n is e4ecutable" if+ )_ name,;
(rint ".n is o&ne# by" if+ )O name,;
(rint ".n!!!!!!!!! Geality ChecNs ";
(rint ".n name e4ists" if+ )e name,;
(rint ".n name has Cero siCe" if+ )C name,;
(rint ".n name contains #ata" if+ )s name,;
(rint ".n is a file" if+ )f name,;
(rint ".n is a #irectory" if+ )# name,;
(rint ".n is a linN" if+ )l name,;
(rint ".n is a socNet" if+ )S name,;
(rint ".n is a (i(e" if+ )( name,;

(rint ".n is a blocN #evice" if+ )b name,;
(rint ".n is a charactor #evice" if+ )c name,;
(rint ".n has setui# bit set" if+ )u name,;
(rint ".n has sticNy bit set" if+ )N name,;
(rint ".n has %i# bit set" if+ )% name,;

(rint ".n is o(en to terminal" if+)t name,;
(rint ".n is a binary file" if+ )B name,;
(rint ".n is a te4t file" if+ )= name,;
(rint ".n!!!!!!!!! Pn# of 'ile Ge(ort: name .n.n";
for+V!:;VXZZZZZ;VWW, 7
(rint " ";
(rint ".b";
F
iWW;
if+i*ZZZ, 7
#ie "Iossible infinite loo(JJJ";
F
F
F
2%.;ibonacci seq&ence ?
Ans : =his co#e (rints out the 'ibonacci sequenceJ
#/LusrLbinL(erl
use &arnin%s;
5fibo ! +:$<,;
to ! RGQ\9:;;

#the loo( of number of fibonaccis to (rint
&hile +count X! to, 7
#this #oes the actual equations
(ush 5fibo$ int+fibo9)<;, W int+fibo9)>;,;
(rint "5fibo9)<;.n";
un#ef 5fibo9:;;
countWW;
F
2+. ;actors ?
Ans : =his (ro%ram %ets factors for a numberJ Can easily be re(ro%ramme# to (rint only (rime
factorsJ
#/LusrLbinL(erl
use &arnin%s;
sub ! RGQ\9:;;
sqrt ! sqrt+sub,;
luc ! :;
(rint "Ilease #o not enter numbers %reater than D #i%its.n" an# e4it if len%th+sub,*D;
#this %ets the (ossible factor an# then checNs it an# if match$ (rints
5(ri!+<JJsub,;
foreach num+>JJsqrt, 7
ne4t unless #efine# (ri9num;;
for +N!numWnum;NX!sqrt;NW!num, 7
un#ef (ri9num;;
Fluc!num an# subL!num an# (rint "luc " if ++sub8num!!:,HH+num*luc,,;F
2.. 9etect & display t1e c&rrent =perating -ystem ?
Ans :
#/LusrLbinL(erl
# Tritten by #>(encil for Dream In Co#e :<L:>L>::E
os6! MO;
# @ere you coul# (erform any testin% o(erations on the result
# 'or e4am(le :
if+os6!!"MSTin?>", 7
(rint "Usin% Microsoft Tin#o&s:.n";
F
else 7
(rint os6;
F
20. Constr&ct t1e c&rrent date 'or a log'ile
Ans :
+Secon#$ Minute$ @our$ Day$ Month$ [ear, ! localtime+time,;
Month ! Month W <; # Increment month by <J
Lon%[ear ! [ear W <Z::; # Set Lon%[earJ
if+[ear *! <::, 7
[ear ! [ear ) <::; # Decrement year by <::J
F
Day ! s(rintf+"8:>#"$Day,;
Month ! s(rintf+"8:>#"$Month,;
[ear ! s(rintf+"8:>#"$[ear,;
@our ! s(rintf+"8:>#"$@our,;
Minute ! s(rintf+"8:>#"$Minute,;
Secon# ! s(rintf+"8:>#"$Secon#,;
currentDate ! [ear J Month J Day;
archiveDate ! Lon%[ear J Month J Day;
current=ime ! "@ourMinuteSecon#";
lo%messa%e ! "archiveDate : current=ime : even starte#";
(rint lo%messa%e; # sen# this to a lo% file
22. C&rrency >,&pee? 9enomination )rogram
Ans : R Sim(le In#ian Gu(ee #enomination Iro%ram in IerlJ
# MOAP[ DPAOMIAR=IOA IGOQGRM
# USIAQ IADIRA GUIPP CUGGPAC[ S[S=PM
# R QOOD IGOQGRM 'OG LPRGAIAQ IPGL IGOQGRMMPGS
# )Sanchit Sarve
# born>c:#e5hotmailJcom
cash!:;
tcash!:;
thou!:;
fhun!:;
hun!:;
ten!:;
ft!:;
t&!:;
five!:;
t&o!:;
one!:;
(rint"Pnter =otal Cash to be #enominate# in Gu(ee:";
chom(+cash!XS=DIA*,;
if+cash %e 1Z1 HH cash le 161,
7
(rint"Ao S=GIAQS RLLOTPD//";
F
else
7
tcash!cash;
thou!int+tcashL<:::,;
tcash)!+thou0<:::,;
hun!int+tcashL<::,;
tcash)!+hun0<::,;
if+hun*!3,
7
fhun!<;
hun)!3;
F
ten!int+tcashL<:,;
tcash)!+ten0<:,;
if+ten*!3,
7
ft!<;
ten)!3;
F
t&!int+tenL>,;
ten)!+t&0>,;
one!tcash;
if+one*!3,
7
five!<;
one)!3;
F
if+one*!>,
7
t&o!int+oneL>,;
one)!+t&o0>,;
F
(rint".n.n.n.n.ncash can be #enominate# into:.n.n";
(rint"thou <:::L) Aotes.n" if+thou/!:,;
(rint"fhun 3::L) Aotes.n" if+fhun/!:,;
(rint"hun <::L) Aotes.n" if+hun/!:,;
(rint"ft 3:L) Aotes.n" if+ft/!:,;
(rint"t& >:L) Aotes.n" if+t&/!:,;
(rint"ten <:L) Aotes.n" if+ten/!:,;
(rint"five 3L) Aotes.n" if+five/!:,;
(rint"t&o >L) Aotes.n" if+t&o/!:,;
(rint"one <L) Aotes.n" if+one/!:,;
(rint".n.n.n )Sanchit Sarve.n";
F
24.@asic -oc"et ?
Ans : Pstablishin% a connection usin% socNet
#/LusrLbinL(erl
LL by tecta
LL tecta>N5%mailJcom ) feel freeJJJ
use strict;
use &arnin%s;
use IO::SocNet::IAP=;
my a##r ! 1ircJo&nsJus1;
my (ort ! 1htt(+E:,1;
my (rot ! 1tc(1;
my socN ! IO::SocNet::IAP=)*ne&+
IeerR##r !* a##r$
IeerIort !* (ort$
IeerIrot !* (rot$
,;
if +socN,
7
my ne&(ort ! trim+(ort$ "htt("$ " ",;
(rint "Connecte#/.n";
(rint "a##r.n";
(rint "ne&(ort.n";
(rint "(rot.n";
F
else
7
(rint "Coul#n1t ConnectJ";
F
35. Converts a 6&mber 'rom any base to any base &sing )#,!.
Ans :
#/(erlJe4e
my +sbase$tbase$sam(le,!5RGQ\;
sbase! %et6in+ 1Pnter the sam(le base:1, unless+sbase ,;
tbase! %et6in+ 1Pnter base to convert to:1, unless+tbase ,;
if+sam(le, 7
(rint convert6base+sbase$sam(le$tbase,$".n";
F else 7
&hile+XS=DIA*, 7
chom(;
(rint convert6base+sbase$6$tbase,$".n";
F
F
sub convert6base 7
my +sbase$sam(le$tbase,!56;
my 5num!s(lit+LL$sam(le,;
my +num$i$5res$5symb$8base,;
foreach+:JJZ$RJJ]$aJJC, 7
(ush 5symb$6;
F
foreach+:JJ5symb)<, 7
base76F!symb96;;
F
5num!reverse+5num,;
foreach+:JJ5num)<, 7
#(rint "Di%it 6 +" J num96; J ", is ";
t!base7num96;F 0 e4(n+sbase$6,;
t!base7num96;F if+6!!:,;
#(rint t J ".n";
numW!t;
F
#(rint "Base is num.n";
&hile+e4(n+tbase$i,X!num, 7
iWW;
F
i));
foreach+:JJi, 7
6!i)6;
res96;!1:1;
&hile+num*!e4(n+tbase$6,, 7
num)!e4(n+tbase$6,;
res96;WW;
F
F
foreach+5res, 7
6!symb96;;
F
5res!reverse+5res,;
return Voin+11$5res,;
F
sub e4(n 7
my +num$e4(n,!56;
my n!<;
foreach+<JJe4(n, 7
n0!num;
F
return n;
F
sub %et6in 7
(rint shift+, J 1 1;
my #ata!XS=DIA*;
chom( #ata;
return #ata;
F
31. 7sing Aip 'iles in perl
Ans : =his co#e creates an# P4tracts ]II 'ilesJ OGIQIARLL[ TGI==PA B[: Traithni4
# Ci(J(l
# Ruthor: Traithni4
use Rrchive::]i( q&+ :PGGOG6CODPS :COAS=RA=S ,;
if +scalar+5RGQ\, X >,7#ie "]i(J(l.nRuthor:Traithni4.nUsa%e: Ci(J(l Xc!create$ 4!e4tract*
Xfilename* Xfiles*.n";F;
my o(t ! shift+5RGQ\,;
my ofile ! shift+5RGQ\,;
# e4tract a Ci( file
if+o(t!KL4Li,7
(rint "]i(J(l.nRuthor:Traithni4.n";
(rint "P4tractin% ofileJJJ.n";
Ci( ! Rrchive::]i()*ne&+,;
#ie 1Prror rea#in% Ci( fileJ1 if Ci()*rea#+ ofile , /! R]6OS;
my 5members ! Ci()*members+,;
foreach element+5members,
7
(rint "element.n";
Ci()*e4tractMember+element,;
F
(rint "Done/.n";
F
# create a Ci( file
if+o(t!KLcLi,7
(rint "]i(J(l.nRuthor:Traithni4.n";
(rint "Creatin% ofileJJJ.n";
my Ci( ! Rrchive::]i()*ne&+,;
foreach my memberAame +ma( 7 %lob F 5RGQ\,
7
if +)# memberAame ,
7
(rint "R##in% memberAame.n";
&arn "Prror a##in% #irectory memberAame.n"
if Ci()*a##=ree+ memberAame$ memberAame , /! R]6OS;
F
else
7
(rint "R##in% memberAame.n";
Ci()*a##'ile+ memberAame ,
or &arn "Prror a##in% file memberAame.n";
F
F
#ie 1Trite errorJ1 if Ci()*&rite=o'ileAame#+ ofile , /! R]6OS;
(rint "Done/.n";
F
32. -pambot *arpit
Ans :=his &ill %enerate# faNe email a##resses &hich can be use# to corru(t an email harvesters
#atabaseJ It also inclu#es a loo(linN$ &hich S@OULD +#e(en#s of the server confi%, brin% it bacN
to the same scri(tJ
#/LusrLbinL(erl )&
# Iossible use: 'aNe a##resses &oul# ren#er an email harvesters #atabase useless
# Ruthor: NuratNull 99R=;; NuratNullJcom
# Create# ^an <<$ >::D ::: e4treme mo#ification for DIC ) May >$ >::D
use &arnin%s;
(rint "Content)ty(e: te4tLhtml.n.n";

#number of emails to %enerate
my count ! :;

#the @=ML co#e W blocNs %oo# robots from %ettin% into an infinite loo(
(rint "Xhtml*Xhea#*XMP=R ARMP.!."robots." COA=PA=.!."nofollo&."*.n";
(rint "Xtitle*ListXLtitle*XLhea#*.n";
(rint "Xh<*";
(rint "=hese a##resses are BOQUS/";
(rint "XLh<*.n";

# start countin%
&hile +count X! RGQ\9:;, 7

# #ata to %enerate the #ifferent (arts of a faNe email a##y
# the ran6Ney sub is Vust %eneratin% ran#om len%th strin%s ma#e out of lo&er ca(ital letters
my ran#om6name ! ran6Ney+ran#+Z,W2,;
my ran#om6#omain ! ran6Ney+ran#+Z,W2,;
my ran#om6fi4 ! ran#+Z,;
my 5fi4 ! +"Jcom"$"Jnet"$"Jor%"$"Jch"$"JV("$"Jus"$"Jru"$"JcoJuN"$"Je#u"$"Jeu",;

# (rint the emails &ith "mailto:" an# maNe them "linN liNe"
(rint 1Xa href!"mailto:1;
(rint ran#om6name$ 151$ ran#om6#omain;
(rint fi49ran#om6fi4;;
(rint 1"*1;
(rint ran#om6name$ 151$ ran#om6#omain;
(rint fi49ran#om6fi4;;
(rint "XLa*";
(rint "XbrL*";
count WW;
F

#the linN that #irects to JJJscri(tJ(lLran#omstrin%Jhtml$ &hich shoul# #is(lay the same scri(t$ may
#e(en# on server settin%s
(rint "Xa href!JL"$ ran6Ney+ran#+B,W2,$ "Jhtml"$"*Some more foo#XLb*XLa*";
(rint "XLbo#y*XLhtml*XbrL*";

#the &orNin%horse behin# the scri(t &hich %enerates the ran#o strin%s
sub ran6Ney 7
my return;
for + < JJ 69:; , 7 return J! chr+ ZD W ran# >3 , F
return return;
F
33. Converts a 9ecimal 6&mber into He$adecimal t1ro&g1 t1e Command !ine.
Ans :
#/(erl
#Qet ar%uments from comman# line
+#ec,!5RGQ\;
#ChecN for invali# info
unless+#ec, 7
(rint ".n.rUsa%e: : X#ecimal number* .n.r";
e4it+,;
F
# (rint #ecimal
(rint "#ecimal number is: #ec.n.r";
# convert to he4 an# (rint results
he4 ! #ec>he4+#ec,;
(rint "he4 number is: he4.n.r";
e4it;
sub #ec>he4 7
# (arameter (asse# to
# the subfunction
my #ecnum ! 69:;;
# the final he4 number
my he4num;
my tem(val;
&hile +#ecnum /! :, 7
# %et the remain#er +mo#ulus function,
# by #ivi#in% by <B
tem(val ! #ecnum 8 <B;
# convert to the a((ro(riate letter
# if the value is %reater than Z
if +tem(val * Z, 7
tem(val ! chr+tem(val W 33,;
F
# 1concatenate1 the number to
# &hat &e have so far in &hat &ill
# be the final variable
he4num ! tem(val J he4num ;
# ne& actually #ivi#e by <B$ an#
# Nee( the inte%er value of the
# ans&er
#ecnum ! int+#ecnum L <B,;
# if &e cant #ivi#e by <B$ this is the
# last ste(
if +#ecnum X <B, 7
# convert to letters a%ainJJ
if +#ecnum * Z, 7
#ecnum ! chr+#ecnum W 33,;
F

# a## this onto the final ans&erJJ
# reset #ecnum variable to Cero so loo(
# &ill e4it
he4num ! #ecnum J he4num;
#ecnum ! :
F
F
return he4num;
F # en# sub
3%. ,andom 6&mber enerator !ist
Ans : R ran#om Aumber %enerator listJ=his scri(t &ill %enerate a list of ran#om numbers that are
not re(eate# in the listJ \ery useful in %eneratin% lotto numbers or anythin% else that you can not
have re(etitive numbersJ OGIQIARL RU=@OG UASAOTAJ
#/LusrLbinL(erl )&
###############################################
## R ran#om Aumber %enerator listJ
## =his scri(t &ill %enerato a list of
## ran#om numbers that are not re(eate#
## in the listJ \ery useful in %eneratin%
## lotto numbers or anythin% else that
## you can not have re(etitive numbers
###############################################
use strict;
use inte%er;
########################################
## Confi%uration:
## 5Aumbers ! a vali# ran%e of numbers
## Limit! a count of ho& many ran#om
##to returnJ =his inclu#es :$ so if
##you (ut >:$ >< numbers &ill be
##returne# in the listJ
########################################
my 5Aumbers ! <JJ2Z;
my Limit ! >:;
my 5list ! +,;
(rint ".n0000000000000000000000000000000000000000000000000000.n";
(rint "00000 =his is a Gan#om number %enerator scri(t 00000.n";
(rint "0000000000000000000000000000000000000000000000000000.n.n.n";
for+my i ! :; i X! Limit; iWW, 7
my intGan# ! int+ran#+5Aumbers,,W<;
#########################################
## R## the first number to the list$ an#
## then com(are all remainin% numbers
## &ith those numbers alrea#y in the list
#########################################
if +i !! :, 7
list9i; ! intGan#;
F
else 7
for +my V ! :; VXi; VWW, 7
&hile +intGan# !! list9V;, 7
#########################################
## =he ran#om number has alrea#y been
## a##e# to the listJ Qenerate a ne&
## Gan#om number an# set the V counter
## to )< so it starts over to see if the
## ne&ly %enerate# number is in the list
#########################################
intGan# ! int+ran#+5Aumbers,,W<;
V ! )<;
F
#########################################
## Te Vust foun# another ran#om number
## that has not been a##e# to the list
## yet$ so &e are a##in% it in no&J
#########################################
list9i; ! intGan#;
F
F
F
(rint "0000000000000000000000000000000000000000000000000000.n";
(rint "00 =his is the list of "J +LimitW<, J" ran#om numbers chosen.n";
(rint "00 by the system in the or#er they &ere chosen.n";
(rint "0000000000000000000000000000000000000000000000000000.n.n";
for +my i ! :; i X!Limit; iWW, 7
(rint "list9i; ";
F
(rint ".n.n.n";
##########################################
## Ao& Sort the Aumeric list of numbers
##########################################
my 5Sorte#List ! sort 7a X!* bF 5list;
(rint "0000000000000000000000000000000000000000000000000000.n";
(rint "00 =his is the Sorte# list of "J +LimitW<, J" ran#om.n";
(rint "00 numbers chosen by the system.n";
(rint "0000000000000000000000000000000000000000000000000000.n.n";
for +my i ! :; i X!Limit; iWW, 7
(rint "Sorte#List9i; ";
F
(rint ".n.n.n";
3+. !ist 7,!Bs in eac1 Action o' !, script
Ans : Lists the UGL1s in each action recor#e# by the loa# runner tool+LG scri(t,J
#/LusrLbinL(erl
5t!Y#ir RGQ\9:;0JcY;
n!#t)>)2;
(rintf"there are 8# files"$n;
5(aram;
for+N!3$i!:;NX!Z;NWW$iWW,
7
(rint ".nt9N;";
if +t9N; !K mLJ7?EF+J0.J,cL,
7
(aram9i;!<;
F
F
foreach line+5(aram,
7
line!reverse+line,;
cho(+line,;
line!reverse+line,;
#b!"RGQ\9:;.."J"line"J"c";
#b !K sL..L....L;
#(rint #b;
##b!"c:..e4er<..Rction<Jc";
o(en +DB$"#b", -- #ie "Can1t O(en file: /.n";
(rint ".nUGL statements in action line.n";
&hile +XDB*,
7
if+6 !K mLUGL!L,
7
(rint ".n6";
F
F
close DB;
F
3.. !ist randomi<er
Ans : Insert a list of items as ar%uments$ se(arate# by "W" an# it &ill (rint them out in ran#om
or#er$ each on its sea(arate line an# equi((e# &ith a sequence numberJ
#/LusrLbinL(erl
use &arnin%s;
my +buffer, ! 5RGQ\;
5list ! s(lit+L.WL$ buffer,;

#=he "ran#om" tasN
5ne& ! q&+,;
&hile +5list, 7
(ush+5ne&$ s(lice+5list$ ran# 5list$ <,,;
F

#Count of numbers before (rinte# list
count ! <;

#Irint numbers an# obVects
foreach obV+5ne&,
7
(rint "count"$ 1J 1;
(rint "obV.n";
countWW;
ne4t;
F
30. ;ormatting a tenCdigit p1one n&mber
Ans : =his sni((et taNes a ten)#i%it (hone number an# formats it$ in the form +444, 444J4444J
sub formatIhoneAumber 7
my number ! shift;
#ie "number is not a vali# <:)#i%it (hone number" unless number !K LM.+U+9<)Z;.#7>F,.,U
9)J$ ;0U+9<)Z;.#7>F,9)J$ ;0U+.#72F,L;
my formatte# ! "+<, >J?";
return formatte#;
F
32. ,everse a given string
Ans :=his scri(t uses the s(lit comman# to s(lit a strin% into an array H then reverses the or#er of
the array elementsJ
#/LusrLbinL(erl
# Tritten by #>(encil DL>BL>::D
(rint ".n!!!!!!! Pnter &or# to reverse: ";
&or#!XS=DIA*;
cho(+&or#,;
5letters!s(lit+un#ef$&or#,;
for+i!:;iXlen%th+&or#,;iWW, 7
(os!len%th+&or#,)i;
5reverse#9i;!5letters9(os)<;;
(rint "i : S&itchin% letters9i; &ith (os : reverse#9i;.n";
F
(rint ".nOut(ut: 5reverse# from 5letters.n";
34. ,andom 6&mbers enerator
Ans : Till %enerate a list of ran#om numbers usin% a hash to insure unique numbers in the final
listJ Rfter looNin% over born>c:#e1s ran#om number %enerator sni((et I thou%ht it coul# be #one a
#ifferent &ay usin% a hash so I &hi((e# this u( loosely base# on his co#eJ
#/LusrLbinL(erl
use strict;
use &arnin%s;
# =his is the ran%e of numbers to
# use to %enerate ran#om sequences fromJ
my 5numbers ! +<JJ2Z,;
# =his is ho& many numbers to %enerateJ
# =his number must be lo&er than the
# total amount of numbers in the above list
# other&ise the scri(t &ill %o into an
# infinite loo(J
my limit ! <<;
# R hash use# to maNe sure &e have
# all unique numbers in the final listJ
my 8list ! +,;
# @ere &e %enerate the list of ran#om
# unique numbersJ =he hash continues to
# buil# until there are limit number
# of NeysJ Since hash Neys must be unique
# &e are left &ith all unique numbers
# &ithout havin% to checN anythin% e4ce(t the
# total number of NeysJ
&hile +Neys 8list X limit, 7
list7numbers9ran# 5numbers;F!<;
F
# (rint unsorte# list of numbers
(rint Voin+1 1$Neys 8list,;
(rint ".n)))))))))))))))))))))))))))))).n";
# (rint sorte# +ascen#in%, list of numbers
(rint Voin+1 1$ sort 7a X!* bF Neys 8list,;
%5. etting Header 8n'ormation
Ans : Qets @ost @ea#er Information usin% IPGLJ
#/LusrLbinL(erl
use IO::SocNet;
5@ea#er;
(rint"Pnter =he @ost: ";
@ost ! XS=DIA*;
cho(+@ost,;
SocNet ! ne& IO::SocNet::IAP=+IeerR##r !* @ost$
IeerIort !* E:$
Iroto!* 1tc(1, -- #ie "Coul# not Connect /.n";
(rint"Connecte#J.n";
(rint"Qettin% @ea#er.n";
(rint SocNet "QP= L @==IL<J:.n.n";
i ! :;
&hile+XSocNet*,
7
5@ea#er9i; ! 6;
iWW;
F
system+"cls",;
i ! :;
(rint"W)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)W.n";
&hile+i X! E,
7
(rint" 5@ea#er9iWW;.n";
F
(rint"W)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)!)W.n.n";
(rint" @ost 'inishe#.n";
%1.D=, enEdeCcryptor
Ans : =his scri(t &ill enable you to encry(t an# #ecry(t strin%s &ith _OGJ It &ill use numbers+the
same len%th as the inserter &or#, as the Ney to #ecry(tJ
#/LusrLbinL(erl

use &arnin%s;
#if you (ress "#"$ the #ecry(tion function is ran$ else$ encry(tion
(rint ".nIress ."#." if you &ant to #ecry(t$ else (ress enter: ";
checN ! Xst#in*;
chom(+checN,;
if + checN !K LM#L , 7
(rint "Insert strin% to #ecry(t: ";
chom(+ #ecr ! Xst#in* ,;
(rint "Insert Ney: ";
chom(+ #eNey ! Xst#in* ,;
##ecry(ts base# on the Ney an# encry(te# strin% (rovi#e#
outc ! #ecr M #eNey;
(rint "[our #ecry(te# strin%: outc.n";
e4it;
F

#if "#" &as not (resse#$ runs this$ encry(tion
(rint "Insert strin% to be encry(te#: ";
chom(+ in(ut ! Xst#in* ,;

#the len%th of the Ney to use &hen cry(tin% this strin%
Ney ! ran6Ney+ len%th+in(ut, ,;

#encry(ts this strin% Ney of the same len%th+Ney are ran# #i%its from :)Z,
4or ! in(ut M Ney;
(rint "Pncry(te# strin%: 4or.n";
(rint "Sey: "$ 4or M in(ut$ ".n";
(rint "Strin%: "$ 4or M Ney$ ".n";

#this sub %enerates the ran#om Ney of the same len%th as the strin% to encry(t
sub ran6Ney 7
my return;
for + < JJ 69:; , 7 return J! chr+ 2E W ran# Z , F
return return;
F
2>J

Potrebbero piacerti anche