#!/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,
In reply to Re: Encrypt/decrypt string in C and Perl
by choroba
in thread Encrypt/decrypt string in C and Perl
by kepler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |