[votazioni] cifrario simmetrico

Stato
Discussione chiusa ad ulteriori risposte.

Oromis92

Utente Silver
22 Dicembre 2007
102
12
2
84
Oromis92
encoder:
Codice:
#!/usr/bin/perl;
# by Oromis92

# octcipher encoder

if (@ARGV < 1) {die "usage: $0 [input file] [>> output file]\n"} else {

while (<>) {
$str .= $_;
}
chomp $str;
@arr = split //, $str;

foreach (@arr) {

$_ = (sprintf("%O",ord($_)))+111;

@arr2 = split //, $_;
for $i (0..scalar(@arr2)) {
$aaa .= '+' x $arr2[$i] . '-';
}

print $aaa;
$aaa = '';
}
print $/;
}

decoder:
Codice:
#!/usr/bin/perl
# by Oromis92

# octcipher decoder

if (@ARGV < 1) {die "usage: $0 [input file] [>> output file]\n"} else {
while (<>) {
$a .= $_;
}
undef $/;
$_ = $a;
$_ =~ y/- / /ds;
@yoda = map{ length } split;
while (@yoda) {
$_ = chr(oct((join('',splice(@yoda,0,3)))-111));
print $_;
}
}
frase:
Codice:
++-+++-+++++--++-++++++-+--++-+++++-++++++--+-+++++-+--++-+++++++-++--++-++++
+++-++++++--++-++++++-++--++-+++++-++++--++-++++++-++++--+-+++++-+--++-+++++-
+++--++-+++++++-+++--++-++++++-++++++++--++-+++++++-++++++++--++-++++++-++++
+++--+-+++++-+--++-+++++-+++++++--++-++++++-++++++++--++-++++++++-+--+-+++++-
+--++-++++++-+++--++-+++++++-++++++--++-++++++-++++++--++-+++++++-+--++-+++++
++-++++--+-+++++-+--++-++++++-++++++++--++-+++++++-+++++++--++-+++++-++++++--
++-+++++++-+++--+-+++++-+--++-+++++++-+++++--++-++++++-+--++-+++++-++++++--+-
+++++-+--++-++++++-+++++--++-+++++-++--++-++++++++-+++--++-++++++++-++--+-+++
++-+--++-+++++-+++++--++-++++++-++++++++--++-+++++-++++++++--+-+++++-+--



robertof
Codice:
<?php
$key = (isset ($argv[2])) ? $argv[2] : 282;
$str = (isset ($argv[1])) ? $argv[1] : "/dev/null";
$mod = (isset ($argv[3])) ? "decode" : "encode";
if (!file_exists ($str)) die ("File non esistente");
$fp = fopen ($str, "r");
$str = fread ($fp, filesize ($str));
fclose ($fp);

if ($mod == "encode") {
    foreach (str_split ($str, 1) as $tmp) {
        $ascii = ord ($tmp) + $key;
        $ascii = str_split ($ascii, 1);
        foreach ($ascii as $newCode) {
            $len = $newCode;
            print (($len==0) ? "+" : str_repeat ("*", $len)).":";
        }
        print "-";
        
    }
} else {
    $tmp = explode ("-", $str);
    array_pop ($tmp);
    foreach ($tmp as $lettera) {
        $total = "";
        foreach (explode (":", $lettera) as $carattere) {
            $total = $total.(($carattere=="+") ? "0" : strlen ($carattere));
        }
        $total = substr ($total, 0, strlen ($total)-1);
        $total = intval ($total) - $key;
        print chr ($total);
        $total = "";
    }
}
    
print "\n";
?>
frase:
Codice:
***:******:******:-***:********:******
:-***:********:***:-***:*:****:-***:*********
:*****:-***:*********:*********:-***:********
:*******:-***:********:*:-***:********:*********
:-***:*:****:-***:********:+:-***:*********:******
:-***:*********:***:-****:+:*:-***:*********:**:-
***:*:****:-***:********:****:-***:*********:***
:-****:+:**:-***:*:****:-***:********:********:-
***:*********:*********:-***:*********:*:-***:
*********:****:-***:*********:*******:-***:*:****
:-***:*********:***:-****:+:+:-***:********:***:
-***:*********:******:-***:*:****:-***:*********
:********:-***:********:******:-***:********:***
:-***:*:****:-***:*********:+:-***:*******:*********
:-****:+:****:-****:+:***:-***:*:****:-***:********
:**:-***:*********:***:-***:********:*****:-**:****
*****:**:-



r4zor_Cr4$h
Codice:
import java.io.*;

public class CifrarioSimmetrico{
    BufferedReader encode;
    BufferedReader decode;

    public void encoder(){
        String text="",result="[",cod="";
        try{
            encode=new BufferedReader(new FileReader("enc.txt"));
            text=encode.readLine();
            if(text.equals("")){
                System.out.println("File Vuoto o non leggibile!");
                System.exit(0);
            }for(int i=0;i<text.length();i++){
                int r=text.charAt(i)-30;
                String a=Integer.toBinaryString(r);
                if(a.length()==6){
                    cod="0"+a;
                }if(a.length()==2){
                    cod="00000"+a;
                }if(a.length()==7){
                    cod=a;
                }
                for(int j=0;j<cod.length();j++){
                    String cod2=""+cod.charAt(j);
                    if(cod2.equals("1")){result+=".";}else{result+="_";}
                }result+="]-[";
            }result=result.substring(0,result.length()-2);
        System.out.println(result);
        encode.close();
        }catch(IOException e){
            System.out.println(e.getMessage());
            System.exit(0);
        }
    }
    public void decoder(){
        String text="",result="",dec2="";
        int count=0;
        try{
            decode=new BufferedReader(new FileReader("dec.txt"));
            text=decode.readLine();
            if(text.equals("")){
                System.out.println("File Vuoto o non leggibile!");
                System.exit(0);
            }text=text.replace("[","");
            text=text.replace("]","");
            text=text.replace("-"," ");
            text=text.replace(".","1");
            text=text.replace("_","0");
            for(int i=0;i<text.length();i++){
                if(!(""+text.charAt(i)).equals(" ")){
                    dec2+=""+text.charAt(i);
                    count++;
                }if(count==7){
                    if(dec2.length()==2){
                       result+=" ";
                    }else{
                        result+=(char)(Integer.parseInt(dec2,2)+30);
                    }
                    count=0;
                    dec2="";
                }
            }System.out.println(result);
            decode.close();
        }catch(IOException e){
            System.out.println(e.getMessage());
            System.exit(0);
        }
    }
}
frase:
Codice:
[_.._.._]-[.__._._]-[.___...]-[_____._]-[._.__..]-[._._...]-[.__._..]-
[.___._.]-[.__.._.]-[_____._]-[.___.__]-[._._.__]-[._.___.]-[._..__.]-
[._.____]-[_____._]-[.__.___]-[._.___.]-[._.._._]-[_____._]-[.__..__]
-[._._...]-[.__....]-[._.__._]-[._._._.]-[_____._]-[._.___.]-[._..___]-
[.___...]-[._._.__]-[_____._]-[._._.._]-[.__._._]-[.___...]-[_____._]-
[.__..._]-[.____..]-[._...__]-[._.._..]-[_____._]-[.___.._]-[._.___.]-
[.__.__.]



meh.
Codice:
#! /usr/bin/env ljs
/*
- Get the binary from the ascii code xor'd 42
- Invert the bits
- Reverse the order
- Move the first 4 bits at the end
- Swap the first bit with the last the second with the seventh etc
- Substitute 1 and 0 with their possible chars
- Add a random char with a 42% chance
*/

require("System/FileSystem/File");

SymmetricCipher = Class.create({
    constructor: function (string) {
        this._string = string;
    },

    methods: {
        encrypt: function () {
            return SymmetrictCrypter.encrypt(this._string);
        },

        decrypt: function () {
            return SymmetrictCrypter.decrypt(this._string);
        },
    },

    static: {
        encrypt: function (string) {
            var result = new String;
            
            for (let i = 0; i < string.length; i++) {
                let bin = (string.charCodeAt(i) ^ 42).toPaddedString(8, 2)
                    .gsub(/0/, '-')
                    .gsub(/1/, '0')
                    .gsub(/-/, '1').reverse();

                let first  = bin.toArray().slice(0, 4);
                let second = bin.toArray().slice(4, 8);

                let byte = [].concat(second).concat(first);

                let tmp = byte.clone();
                for (let h = 0; h < tmp.length; h++) {
                    [byte[h], byte[byte.length-1-h]] = [tmp[tmp.length-1-h], tmp[h]];
                }

                for each (let bit in byte) {
                    result += (bit == 0)
                        ? SymmetricCipher.zeroes[int(Math.random()*SymmetricCipher.zeroes.length)]
                        : SymmetricCipher.ones[int(Math.random()*SymmetricCipher.ones.length)]

                    if (Math.random()*100 < 42) {
                        let ch;
                        while (!(ch = int(Math.random()*120).toChar()).test(/[0-9A-Za-z\n\"\'\&\|\*\^\=]/));
                        result += ch
                    }
                }
            }

            return result;
        },

        decrypt: function (string) {
            var result = new String;

            var binary = string.gsub(/[0-9A-Za-z\n\"\'\&\|\*\^\=]/, '')
                .gsub(new RegExp("["+RegExp.escape(SymmetricCipher.zeroes.join(''))+"]"), '0')
                .gsub(new RegExp("["+RegExp.escape(SymmetricCipher.ones.join(''))+"]"), '1');

            var chars = binary.splitEvery(8);
            for each (let char in chars) {
                char    = char.toArray();
                let tmp = char.clone();
                for (let h = 0; h < tmp.length; h++) {
                    [char[h], char[char.length-1-h]] = [tmp[tmp.length-1-h], tmp[h]];
                }

                let first  = char.slice(4, 8);
                let second = char.slice(0, 4);

                let bin = [].concat(first).concat(second).join('').reverse()
                    .gsub(/1/, '-')
                    .gsub(/0/, '1')
                    .gsub(/-/, '0');

                result += (bin.fromBase(2) ^ 42).toChar();
            }

            return result;
        },

        zeroes: ['/', '$', '[', ']', '{', '~', ')', '@', '#', '_', ',', ';', '.', ':'],
        ones:   ['+', '-', '%', '?', '}', '<', '>', '(', '!'],
    }
});

Object.extend(String.prototype, {
    symEncrypt: function () {
        return SymmetricCipher.encrypt(this);
    },

    symDecrypt: function () {
        return SymmetricCipher.decrypt(this);
    },
});

if (arguments.length < 1) {
    die("You have to pass at least a path.");
}

if (arguments.length == 1) {
    print(new File(arguments[0], File.Mode.Read).readToEnd().symEncrypt());
}
else if (arguments.length > 1) {
    switch (arguments[0]) {
        case '-e':
        if (arguments.length == 2) {
            print(new File(arguments[1], File.Mode.Read).readToEnd().symEncrypt());
        }
        else {
            new File(arguments[2], File.Mode.Write).write(new File(arguments[1], File.Mode.Read).readToEnd().symEncrypt())
        }
        break;

        case '-d':
        if (arguments.length == 2) {
            print(new File(arguments[1], File.Mode.Read).readToEnd().symDecrypt());
        }
        else {
            new File(arguments[2], File.Mode.Write).write(new File(arguments[1], File.Mode.Read).readToEnd().symDecrypt())
        }
        break;

        case '-o':
        switch (arguments[1]) {
            case '-e':
            print(arguments[2].symEncrypt());
            break;

            case '-d':
            print(arguments[2].symDecrypt());
            break;

            default:
            print(arguments[1].symEncrypt());
            break;
        }
        break;

        default:
        if (arguments.length == 2) {
            new File(arguments[1], File.Mode.Write).write(new File(arguments[0], File.Mode.Read).readToEnd().symEncrypt())
        }
        else {
            die("You just lost the game.");
        }
        break;
    }
}
frase:
Codice:
,@~%-,;,%(;S%+[>n+;_@:g>D{a!?J.D<B$(K++0<!_q?)t@=+f,Q(/=,2)@.}#C<d@'-X%{#S%,%}f_!-b;}G~t-N}(o-}$7-$}5!@%)>-!2-g(R:(q<4?q>R_T<-#}K}c!C(]>/U<[!;-@!m!$',>J$(@*+;}s:c?+!I#}+;i>_o%+?}!:e_<%!C)V}6?},Z}D#}U]+>}>[U>>E.?Q.)>.C}>6%!D?s(+!!=?#-%/~5.3;0?I.?X/%A_]E[}t_?9<n/!v;<Q%w@>@;-}N$Y}8@%
~")J+$>-+d%%!b]2?/v-)+-U/_!}<g/-.$J[,)!)3}>_-a+<>V/-&{{<@%V<!l%Z-:]@>>/<g)d-F(Z,}%.F}J%_[
){8(_X!+$n!Q_<E>}++!;X.?Q!~}j<_-$@}[-l>}!!}}L#Z(:-H(L$#}a[%.g/i+{-B<0??W!;[c~A(e+g:!}};b(@!$N-s>B.K#!)-5@p<I<
_wizard
php:
Codice:
<?php
error_reporting("E_ALL ~E_NOTICE");
function numbstr_encrypt($str) {
    for($i=0;$i<strlen($str);$i++) {
        $nums[] = ord($str[$i]);
    }
    for($i=0;$i<count($nums);$i++) {
        $c += $nums[$i];
    }
    $c = floor($c / strlen($str));
    while($c > 10) {
        $c = floor($c / 2);
    }
    for($i=0;$i<count($nums);$i++) {
        $nums[$i] *= $c;
    }
    return join("",$nums).$c;
}
function numbstr_decrypt($num) {
    $c = 1;
    settype($num,"string");
    $k = $num[strlen($num)-1];
    for($i=0;$i<strlen($num);$i++) {
        if($c != 4) {
            $prov .= $num[$i];
            $c++;
        } else {
            $nums[] = $prov;
            unset($prov);
            $prov = $num[$i];
            $c = 2;
        }
    }
    for($i=0;$i<count($nums);$i++) {
        $nums[$i] /= $k;
    }
    for($i=0;$i<count($nums);$i++) {
        $nums[$i] = chr($nums[$i]);
    }
    return join("",$nums);
}
?>
perl:
Codice:
use integer;
sub encrypt {
    $str = shift;
    for($i=0;$i<length($str);$i++) {
        $arr[$i] = ord(substr($str,$i,1));
    }
    for($i=0;$i<$#arr;$i++) {
        $c += $arr[$i];
        $c /= $#arr;
    }
    $c /= 2 while($c > 10);
    for($i=0;$i<=$#arr;$i++) {
        $arr[$i] = $arr[$i] * $c;
    }
    return join("",@arr).$c."\n";
}

sub decrypt {
    $str = shift;
    @s = split //,$str;
    $k = $s[$#s];
    $c = 1;
    for($i=0;$i<length($str);$i++) {
        if($c != 4) {
            $ret .= $s[$i];
            $c++;
        } else {
            push @nums, $ret;
            $ret = $s[$i];
            $c = 2;
            }
    }
   for($i=0;$i<length(join("",@nums));$i++) {
        $nums[$i] = chr($nums[$i] / $k);
    }
    return (join "", @nums)."\n";
}




greyfox
Codice:
#!/usr/bin/ruby
require "base64"
$_fnc=[
"X3I9IiIKX3Muc3BsaXQoIiAiKS5lYWNoe3xjfApjPWMudG9faS0zMApjLnRvX3MuZWFjaF9ieXRle3xj​MHwKIF9yKz0oYzAuY2hyLnRvX2k+MCkgPyAiLSIq
YzAuY2hyLnRvX2kgOiAiXyIKX3IrPSIsIgp9Cl9yPV9yWzAsX3IubGVuZ3RoLTFdCl9yKz0iLiIKfQpf​cgo=",
"X3I9IiIKX2xsPSIiCl9zLnNwbGl0KC8gLykuZWFjaHt8bnwKbj1uLnRvX2kudG9fcygyKQpuPSIwIitu​IHVudGlsIG4ubGVuZ3RoPT04Cm4uZWFjaF9ieXRl
e3xiYnwKX2xsKz1iYi5jaHIKaWYgX2xsLmxlbmd0aD09Mgpfcis9KDM1K19sbC50b19pKS5jaHIrIn4i​Cl9sbD0iIgplbmQKfQp9Cl9yCg==",
"Cl9yPScnCl9zLnNwbGl0KCIgIikuZWFjaHt8bXwKbT1tLnRvX2leNwpfcis9KChtPjMzIGFuZCBtPD0x​MjApID8gbS5jaHIgOiAiXiIrbS50b19zKSsiISIK
fQpfclswLi4uLTFdCg=="
]
$_dec=[
"X3I9IiIKX3Muc3BsaXQoIi4iKS5lYWNoe3xxfApxLnNwbGl0KCIsIikuZWFjaHt8d3wKX3IrPSh3PT0i​XyIpID8gIjAiIDogdy5sZW5ndGgudG9fcwp9Cl9y
Kz0iICIKfQpfcjA9IiIKX3Iuc3BsaXQoIiAiKS5lYWNoe3xlfAplPShlLnRvX2krMzApLnRvX3MKZT0i​MCIrZSB1bnRpbCBlLmxlbmd0aD09MwpfcjArPWUr
IiAiCn0KX3IwWzAsX3IwLmxlbmd0aC0xXQo=",
"X3I9IiIKX2s9JycKX3Muc3BsaXQoIn4iKS5lYWNoe3x2fAp2PSh2WzBdLnRvX2ktMzUpLnRvX3MKX2sr​PSh2Lmxlbmd0aD09Mik/IHYgOiAnMCcrdgppZiBf
ay5sZW5ndGg9PTgKX2s9X2sudG9faSgyKS50b19zCl9rPScwJytfayB1bnRpbCBfay5sZW5ndGg9PTMK​X3IrPV9rKyIgIgpfaz0nJwplbmQKfQpfclswLi4u
LTFdCg==",
"X3I9JycKX3Muc3BsaXQoLyEvKS5lYWNoe3xtfAptPShtWzAsMV09PSJeIikgPyBtWzEuLi0xXSA6IG1b​MF0udG9fcwptPW0udG9faV43Cl9yKz1tLnRvX3Mr
IiAiCn0KX3JbMC4uLi0xXQ=="
]
def gogo(ff)
_rs=""
ff.split(":").each{|q|
_rs+=q.to_i.chr.to_s
}
_rs
end
$_out="\n"+Base64.decode64("ZGVmIGdvZ28oZmYpCl9ycz0iIgpmZi5zcGxpdCgiICIpLmVhY2h7fHF8Cl9ycys9cS50b19pLmNoci50 ​b19zCn0KX3JzCmVuZAo=")+"\n"
$_cmt="#\n#\n#  By GreyFox -> http://www.cyberfox.netsons.org\n#\n#"
$_gv=[]

def encode(_s)
_g=rand($_fnc.length).to_i
_rr1=Base64.decode64($_fnc[_g])
_rr2=Base64.decode64($_dec[_g])
if !$_gv.include?(_g)
$_out+="def dec_"+_g.to_s+"(_s)\n"+_rr2+"\nend\n"
$_gv.push(_g)
end
$_out+="print gogo dec_"+_g.to_s+"(\""+eval(_rr1).to_s+"\")\n"
end

if !ARGV[0] || ARGV[1]
puts "usage fif0 <file>"
exit 0
end
if !File.file?(ARGV[0])
puts "Sorry, I can't read "+ARGV[0]+"."
exit 0
end
_nc=File.size?(ARGV[0])
ran=rand(4)
_nc/=10 until _nc<ran+3

File.open(ARGV[0]) do |_f|
_ncc=1
_ss=""
_f.each_byte{|c| c=c.to_s
c="0"+c until c.length==3
_ss+=" "+c

if(_ncc==4)
_ncc=0
encode(_ss)
_ss=""
end
_ncc+=1
}
File.open "encoded.rb", "w" do |_outfile|
    _outfile << "#!/usr/bin/ruby\n"+$_cmt+"\n"+$_out+"puts \"\n\"\n#--->end encoded file"
end
puts "encoded string @ ./encoded.rb"
end
frase:
Codice:
#!/usr/bin/ruby
#
#
#  By GreyFox -> http://www.cyberfox.netsons.org
#
#

def gogo(ff)
_rs=""
ff.split(" ").each{|q|
_rs+=q.to_i.chr.to_s
}
_rs
end

def dec_1(_s)
_r=""
_k=''
_s.split("~").each{|v|
v=(v[0].to_i-35).to_s
_k+=(v.length==2)? v : '0'+v
if _k.length==8
_k=_k.to_i(2).to_s
_k='0'+_k until _k.length==3
_r+=_k+" "
_k=''
end
}
_r[0...-1]

end
print gogo dec_1("#~#~#~#~$~$~$~#~$~-~-~#~$~-~$~$~#~-~#~#~")
def dec_0(_s)
_r=""
_s.split(".").each{|q|
q.split(",").each{|w|
_r+=(w=="_") ? "0" : w.length.to_s
}
_r+=" "
}
_r0=""
_r.split(" ").each{|e|
e=(e.to_i+30).to_s
e="0"+e until e.length==3
_r0+=e+" "
}
_r0[0,_r0.length-1]

end
print gogo dec_0("--------,---.--------,-------.-------,-----.------,---------.")
print gogo dec_1("#~#~#~#~$~-~-~.~#~-~#~#~$~-~#~-~$~.~#~-~")
print gogo dec_1("#~#~#~#~$~-~.~.~$~.~$~.~$~-~.~-~#~-~#~#~")
def dec_2(_s)
_r=''
_s.split(/!/).each{|m|
m=(m[0,1]=="^") ? m[1..-1] : m[0].to_s
m=m.to_i^7
_r+=m.to_s+" "
}
_r[0...-1]
end
print gogo dec_2("a!h!^127!'")
print gogo dec_2("m!r!j!w")
print gogo dec_2("t!'!h!q")
print gogo dec_2("b!u!'!s")
print gogo dec_0("-------,----.-------,-.--.-------,--------.")
print gogo dec_2("f!^125!^126!'")
print gogo dec_2("c!h!`!)")
puts "
"
#--->end encoded file



le votazioni si chiudono il giorno di pasqua a mezzogiorono (12/mar/2009 12:00)
 
[ot]Oromis, copiando da pastebin hai copiato tutti i <li>, copia dalla textarea se no e' brutto :S
E magari converrebbere includere anche la stringa criptata d'esempio :p[/ot]
 
Volevo scrivere semplicemente la parola "meh" in questo post ma dice che il messaggio è troppo corto, quindi lo allungo, ma non cambia il fatto che voti meh
 
[ot]
meh, ho rivisto il tuo algoritmo. Il pezzo nel quale scambi il primo bit con l'ultimo, il secondo con il settimo etc... , non equivale ad un banalissimo reverse() ???
[/ot]
 
Cosa ho vinto?

[ot]Ah e per il possibile reverse, non ho voglia di pensare, ma non credi sia un vero reverse, e' un incrocio, boh :O[/ot]
 
Stato
Discussione chiusa ad ulteriori risposte.