Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Encrypt/decrypt string in C and Perl

by choroba (Cardinal)
on Sep 18, 2016 at 13:35 UTC ( [id://1172053]=note: print w/replies, xml ) Need Help??


in reply to Encrypt/decrypt string in C and Perl

I've never really programmed in C, but I tried the following:
#!/usr/bin/perl use warnings; use strict; my $str = shift; my $key = join q(), map chr rand 255, 0 .. 255; print "$key\n"; my $encrypted = $str ^ substr($key,0,length($str)); print "$encrypted\n";

#include<stdio.h> int main () { char key[255], string[255]; gets(key); gets(string); for (int i=0;string[i] != 0;i++) { printf("%c", key[i] ^ string[i]); } return 0; }

The ^ operator doesn't seem to work for strings, so I had to iterate the strings character by character.

It seems to work sometimes , I'm not sure why not always. Maybe you can get 0 as a result of the xor somewhere in the middle of a string? Or a newline in the middle of the key? But it should get you started.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Encrypt/decrypt string in C and Perl
by kepler (Scribe) on Sep 18, 2016 at 13:38 UTC
    It seems a very good start!!! Thanks :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-16 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found