Page 2 of 2

Re: script to encrypt messages, please

Posted: 15 May 2011 20:19
by admin
OK, try this with v9.90.0927:

Code: Select all

"Encrypt Clipboard"
  global $string, $chars, $charsrnd;
  sub "_shared";
  text replacelist($string, $chars, $charsrnd, "", 1);
"Decrypt Clipboard"
  global $string, $chars, $charsrnd;
  sub "_shared";
  text replacelist($string, $charsrnd, $chars, "", 1);
"_shared"
  global $string, $chars, $charsrnd;
  $string = "<clipboard>";
  $key = input("Enter Key<crlf>The same key has to be used for encryption and decryption.", "Can be any string." , "Venus");
  $seedhex = hash("crc32", $key); //e.g. AEEF2A50
  $seed = hextodec($seedhex);
  $chars = ' .,;:!?*"#_-+()<>[]{}/\=$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  $charsrnd = formatlist($chars, "cx", "", $seed);

Re: script to encrypt messages, please

Posted: 17 May 2011 02:22
by tiago
works a treat, Don, thank you very much.
Any chance to have a complimentary full dec2hex...?

Re: script to encrypt messages, please

Posted: 18 May 2011 13:59
by Stefan
admin wrote:OK, try this with v9.90.0927:

Code: Select all

v9.90.0926 - 2011-05-15 13:50
    + SC formatlist enhanced: Added format "x" for shuffle (randomize
      order), and a special parameter for a seed.
v9.90.0927 - 2011-05-15 20:22
    + Scripting got a new function.
      Name:   hextodec
WOW, that's really cryptically and fast :D Thank you Don.

Code: Select all

:cMM(1=yg6-My10=Wfo6:Vr=yZrq6_Wfg(!r6a86sbbI86dWr=086$+86sbb#86sbbb86DR86ty86KI?6{(=G6#sv*W=60fg6z]v*W=6jy1rW(fr86!Gy1y60MMhW\0*hy8601y6rcMM(1=yg?
$5Mh(1y16Wr606+(1=0*hy6UWhy6t0f0oy1?6Q=6g(yrf'=61yOcW1y60fV6Wfr=0hh0=W(f6(16\G0foyr6=(6V(c16rVr=yZ6(161yoWr=1V?6:=W\X!01y86Wgy0h6E(1606,:{6g1Wjy?
R0**yg6{1(!rWfo?6}c==Wfovygoy6EWhy6Z0f0oyZyf=6crWfo606=1cy6Zch=Wv=0**yg6Wf=y1E0\y?
RGy6(M=W(f0h6Ac0h6+0fy6Z(gy6rMyhhr6M1(gc\=WjW=V60fg6y0ry6(E6cry86yrMy\W0hhV6E(16=G(ry6\(ZWfo6E1(Z60f6(1=G(g(96EWhy6Z0f0oy1?6 y01f6Z(1y???
tch=Wv yjyh6,fg(JFyg(6E(16EWhy6(My10=W(fr86r=(1yg6*y=!yyf6ryrrW(fr860hh(!r6V(c6=(6EW96=(g0V6!G0=6V(c6*1(Xy6Vyr=y1g0V?6 y01f6Z(1y???
Ccycyg6UWhy6-My10=W(fr6!W=G6*0\Xo1(cfg6M1(\yrrWfo?6nf/(V6=Gy6rMyyg60fg6r0Ey=V6(E606}(MV6Ccycy?6 y01f6Z(1y???
+(!y1Ech6UWhy6:y01\G6!W=G60Z0xWfo6rMyyg?6Q=6rcMM(1=r6{((hy0f6 (oW\86Fyoch016n9M1yrrW(fr86{((hy0f6Fyon9M86}(f=yf=6:y01\G860fg6Z(1y???
R0ov{0ryg6UWhy6t0f0oyZyf=6rcMM(1=r60rrWofWfo6WfgWjWgc0h6h0*yhr86=0or860fg6\(ZZyf=r6=(60fV6EWhy60fg6E(hgy1?6t(1y???



I did my own test and integrated an line wrap for the encrypted text:
(not fully tested yet, and room for improvement, f.ex. to code an Base64 tool)


FROM:
Supported Operating Systems: Windows 7, 2008, Vista, XP, 2003, 2000, NT, Me, 98. Both 32-bit and 64-bit versions, where applicable, are supported.
XYplorer is a Portable File Manager. It doesn't require any installation or changes to your system or registry. Stickware, ideal for a USB drive.

TO:
:cMM(1=yg6-My10=Wfo6:Vr=yZrq6_Wfg(!r6a86sbbI86dWr=0
6$+86sbb#86sbbb86DR86ty86KI?6{(=G6#sv*W=60fg6z]v*W=
jy1rW(fr86!Gy1y60MMhW\0*hy8601y6rcMM(1=yg?BBB {BBB$
Mh(1y16Wr606+(1=0*hy6UWhy6t0f0oy1?6Q=6g(yrf'=61yOcW
y60fV6Wfr=0hh0=W(f6(16\G0foyr6=(6V(c16rVr=yZ6(161yo
r=1V?6:=W\X!01y86Wgy0h6E(1606,:{6g1Wjy?

And Back use

Code: Select all

//not fully tested yet:
"Encrypt Clipboard"
    global $string, $chars, $charsrnd, $StrToEnc;
    //join lines to make one long string:
    $StrToEnc = regexreplace("<clipboard>", "\r\n*", "###LB###");
    //do encrypting:
    sub "_shared";
    $encry = replacelist($string, $chars, $charsrnd, "", 1);
    //split encrypted text into short lines like Base64:
    $LineWrap = $encry;
    $temp="";
    while (strlen($LineWrap) > 51){
      $temp = $temp . substr($LineWrap, 0, 51) . "<crlf>";
      $LineWrap = substr($LineWrap,52);}
    $out = $temp$LineWrap;
    text $out;


"Decrypt Clipboard"
    global $string, $chars, $charsrnd, $StrToEnc;
    $StrToEnc = "<clipboard>";
    //join wrapped encrypted lines:
    $StrToEnc = regexreplace($StrToEnc, "\r\n", "");
    //do decrypting:
    sub "_shared";
    $decry = replacelist($string, $charsrnd, $chars, "", 1);
    //split encrypted joined lines again at original line break:
    $out = regexreplace($decry, "###LB###", "<crlf>");
    text $out;

"_shared"
    global $string, $chars, $charsrnd, $StrToEnc;
    $string = $StrToEnc; //"<clipboard>";
    $key = input("Enter Key<crlf>The same key has to be used for encryption and decryption.", "Can be any string." , "Venus");
    $seedhex = hash("crc32", $key); //e.g. AEEF2A50
    $seed = hextodec($seedhex);
    $chars = ' .,;:!?*"#_-+()<>[]{}/\=$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    $charsrnd = formatlist($chars, "cx", "", $seed);
  

Re: script to encrypt messages, please

Posted: 18 May 2011 14:11
by admin
But note that this "encryption" is easily breakable by letter frequency analysis...

BTW, this might be a slightly cooler way to organize my previous code (damn, it's time I add user functions...):

Code: Select all

"Encrypt Clipboard"
  global $encrypt; $encrypt = 1;
  sub "_shared";
"Decrypt Clipboard"
  global $encrypt; $encrypt = 0;
  sub "_shared";
"_shared"
  global $encrypt;
  $string = "<clipboard>";
  $key = input("Enter Key<crlf>The same key has to be used for encryption and decryption.", "Can be any string." , "Venus");
  $seedhex = hash("crc32", $key); //e.g. AEEF2A50
  $seed = hextodec($seedhex);
  $chars = ' .,;:!?*"#_-+()<>[]{}/\=$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  $charsrnd = formatlist($chars, "cx", "", $seed);
  if ($encrypt) {
    text replacelist($string, $chars, $charsrnd, "", 1);
  } else {
    text replacelist($string, $charsrnd, $chars, "", 1);
  }

Re: script to encrypt messages, please

Posted: 18 May 2011 14:46
by Stefan
admin wrote:[...] (damn, it's time I add user functions...):
[...]
YES, please :D 8)


EDIT:

Please also with
#include <xydata>\funcs\common.xys




.

Re: script to encrypt messages, please

Posted: 18 May 2011 15:01
by admin
Stefan wrote:
admin wrote:[...] (damn, it's time I add user functions...):
[...]
YES, please :D 8)
:)

Concerning your line wrap. In the next version try this. "p" = perforate... :mrgreen:
text formatlist("abcdefg", "rp", , 2); //g|ef|cd|ab
text formatlist("abcdefg", "p", "." , 1); //a.b.c.d.e.f.g

Re: script to encrypt messages, please

Posted: 20 May 2011 13:22
by Stefan
admin wrote:
Stefan wrote:
admin wrote:[...] (damn, it's time I add user functions...):
[...]
YES, please :D 8)
:)

Concerning your line wrap. In the next version try this. "p" = perforate... :mrgreen:
text formatlist("abcdefg", "rp", , 2); //g|ef|cd|ab
text formatlist("abcdefg", "p", "." , 1); //a.b.c.d.e.f.g

Code: Select all

v9.90.0931 - 2011-05-18 15:31
    + SC formatlist enhanced: Added format "p" for perforate.
      Syntax: formatlist(list, [format], [separator=|], [param])
        format:   Switches for the desired formatting. Can be freely
                  combined in any order.
          p = perforate (split by length of parts, not by separator)
        param:    On format p: Length of parts the list shall be split
                  into. If missing or smaller than 1 it is set to 1.
      Examples:
        text formatlist("abcdefg", "pr", , 2); //g|ef|cd|ab
        text formatlist("abcdefg", "p", "." , 1); //a.b.c.d.e.f.g
WOW thanks, works pretty fine.

Code: Select all

"Encrypt Clipboard"
    global $string, $chars, $charsrnd, $StrToEnc;
    //join lines to make one long string:
    $StrToEnc = regexreplace("<clipboard>", "\r\n*", "###LB###");
    sub "_shared";
    $decry = replacelist($string, $chars, $charsrnd, "", 1);
    //           formatlist(   list  , [format], [separator=|], [param])
    $decry = formatlist($decry,     "p"    ,     "<crlf>"    ,    40    ); //wrap output at pos 40, needs XY v9.90.0931 
    text $decry;

"Decrypt Clipboard"
    global $string, $chars, $charsrnd, $StrToEnc;
    $StrToEnc = "<clipboard>";
    //join wrapped encrypted lines:
    $StrToEnc = regexreplace($StrToEnc, "\r\n", "");
    sub "_shared";
    $decry = replacelist($string, $charsrnd, $chars, "", 1);
    //split lines again:
    $out = regexreplace($decry, "###LB###", "<crlf>");
    text $out;

"_shared"
    global $string, $chars, $charsrnd, $StrToEnc;
    $string = $StrToEnc; //"<clipboard>";
    $key = input("Enter Key<crlf>The same key has to be used for encryption and decryption.", "Can be any string." , "Venus");
    $seedhex = hash("crc32", $key); //e.g. AEEF2A50
    $seed = hextodec($seedhex);
    $chars = ' .,;:!?*"#_-+()<>[]{}/\=$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    $charsrnd = formatlist($chars, "cx", "", $seed);

Output:

With (regexreplace("<clipboard>", "\r\n*", "###LB###")) disabled:
(Just to see the effect)

Code: Select all

:cMM(1=yg6-My10=Wfo6:Vr=yZrq6_Wfg(!r6a86
sbbI86dWr=086$+86sbb#86sbbb86DR86ty86KI?
6{(=G6#sv*W=60fg6z]v*W=6jy1rW(fr86!Gy1y6
0MMhW\0*hy8601y6rcMM(1=yg?
$5Mh(1y16Wr6
06+(1=0*hy6UWhy6t0f0oy1?6Q=6g(yrf'=61yOc
W1y60fV6Wfr=0hh0=W(f6(16\G0foyr6=(6V(c16
rVr=yZ6(161yoWr=1V?6:=W\X!01y86Wgy0h6E(1
606,:{6g1Wjy?
and with join input lines enabled:

Code: Select all

:cMM(1=yg6-My10=Wfo6:Vr=yZrq6_Wfg(!r6a86
sbbI86dWr=086$+86sbb#86sbbb86DR86ty86KI?
6{(=G6#sv*W=60fg6z]v*W=6jy1rW(fr86!Gy1y6
0MMhW\0*hy8601y6rcMM(1=yg?BBB {BBB$5Mh(1
y16Wr606+(1=0*hy6UWhy6t0f0oy1?6Q=6g(yrf'
=61yOcW1y60fV6Wfr=0hh0=W(f6(16\G0foyr6=(
6V(c16rVr=yZ6(161yoWr=1V?6:=W\X!01y86Wgy
0h6E(1606,:{6g1Wjy?

Re: script to encrypt messages, please

Posted: 22 May 2011 18:02
by tiago
Great work with the "join input lines" Stefan.
Does a difference for a paranoid control freak like me. 8)

Re: script to encrypt messages, please

Posted: 01 Jul 2011 23:31
by tiago
Any ideas on how to achieve a scripted manner to break the letter frequency analysis deciphering method?
I'm trying to map and randomly reshuffle letters but haven't developed any reliable way to get it done.
Tip: without external tools thus no conventional encryption allowed.