Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

RE: Re: encryption

by Adam (Vicar)
on Nov 07, 2000 at 05:09 UTC ( #40299=note: print w/replies, xml ) Need Help??


in reply to Re: encryption
in thread encryption

#!/usr/bin/perl -w use strict; # $_ = "V'z abg fnlvat lbh nfxrq n ubzrjbex dhrfgvba..."; $_ = "Ohg vg'f ernyyl n irel fvzcyr gnfx..."; my %ceaser; @ceaser{'A'..'Z','a'..'z',' ','.',"'"} = ('N'..'Z','A'..'M', 'n'..'z', 'a'..'m', ' ','.',"'"); my $decoded; $decoded .= $ceaser{$_} for split //; print $decoded, "\n";

Replies are listed 'Best First'.
RE: RE: Re: encryption
by jlp (Friar) on Nov 07, 2000 at 05:50 UTC
    Slightly more compact:
    #!/usr/bin/perl -w use strict; $_ = "Ohg vg'f ernyyl n irel fvzcyr gnfx..."; tr/A-Za-z/N-ZA-Mn-za-m/; print;
      and a byte more compact: #!/usr/bin/perl -w use strict; $_ = "Ohg vg'f ernyyl n irel fvzcyr gnfx..."; y/A-Za-z/N-ZA-Mn-za-m/; print;
      thank you for doing my homework now im sure to gat an 'A+"
RE: RE: Re: encryption
by blogan (Monk) on Nov 07, 2000 at 05:26 UTC
    Minor change, but now you don't have to define what happens for characters that shouldn't be "decrypted".
    #!/usr/bin/perl -w use strict; $_ = "Ohg vg'f ernyyl n irel fvzcyr gnfx..."; my %caesar; @caesar{'A'..'Z','a'..'z'} = ('N'..'Z','A'..'M', 'n'..'z', 'a'..'m'); my $decoded; $decoded .= $caesar{$_} ? $caesar{$_} : $_ for split //; print $decoded, "\n";
      #!/usr/bin/perl -w use strict; my $line = "Lbh pbhyq rira hfr n gvrq inevnoyr... 3-)"; my %caesar; @caesar{'A'..'Z','a'..'z',0..9} = ('N'..'Z','A'..'M', 'n'..'z', 'a'..'m', 5..9,0..4 ); sub TIESCALAR{bless[pop]} sub FETCH{exists $caesar{$_}?$caesar{$_}:$_} tie my $chars, '', ''; print $chars for split //, $line;
      Although I like the use of transpose more.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://40299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2023-09-30 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?