Page 1 of 2

script to encrypt messages, please

Posted: 21 Apr 2011 20:55
by tiago
I tried hard to get this working but >sigh<.
So I ask anyone out there to write me a script to encrypt/decrypt messages using a simple table of replacements like abc123>>dtg951 as key, in the sense that each letter must have a correspondence, comma-separated or not, similarly to what search and replace does ("Ä|Ö|Ü|ä|ö|ü>>Ae|Oe|Ue|ae|oe|ue"). Question and exclamation marks could have a replacement, if necessary, so the script must be very flexible.

My attempts worked fine to full strings but failed completely on whole messages.

Thanks in advance.

Re: script to encrypt messages, please

Posted: 21 Apr 2011 21:36
by Stefan
Do you know Rot13 "encryption" (or better "stashing")?

ABCDEF becomes NOPQRS
and
NOPQRS becomes ABCDEF

Just check out this Rot13 script over there if this is enough for your issue >>> http://www.xyplorer.com/xyfc/viewtopic. ... 556#p44556


Maybe this >> Encryption: Would A File Encryption Tool Be Useful Feature? thread will be from use too?


 

Re: script to encrypt messages, please

Posted: 22 Apr 2011 00:38
by tiago
The problem with provided Rot13 solution is not having unique keys to serve as base for the table of replacements to cypher/decipher the message.

In case the key for "ABCDEF" can be anything, being "anything" the whole alphabet randomized (capitalization matters for the key!) or simply any given amount of letters.
So

ABCDEF >> key: hjKoPH, CAFE >>> KhHP
abcde...ABC...F... >> key: 12345...BCD...G..., Face >>> G135
AaBbCc...YyZz >> key: HhKkMm...EeGg, Zyca >>> Gemh

Since you mentioned randomization the cyphering process could generate its own deciphering key/table of replacements. I think it would not be hard to take that and introduce one's own key either, if necessary. Randomization of key in other words involves replacing letters/numbers with other letters/numbers in different positions/casing, but ensuring uniqueness in the key so each alphanumeric seed will have a unique correspondent pair in the key. Hope this is clear.
And yes, it's desirable support to other characters.

Key sample (small problem: numbers have no randomized position):

p,f,d,j,s,x,k,y,h,t,l,a,r,b,u,q,z,v,e,o,n,c,i,g,m,w,1,2,3,4,5,6,7,8,9,0,
W,O,Z,U,I,E,R,K,S,J,P,F,N,B,L,H,A,X,Q,T,C,V,D,M,G,Y
I had asked for a predictable dedupe or sorting in formatlist() earlier among other reasons because it would be more easy to check correctness of such seeds if, when sorted, I could read Aa,Bb,Cc instead of current aA,Bb,Cc and so on.

Re: script to encrypt messages, please

Posted: 27 Apr 2011 14:27
by admin
Check out SC replacelist().

Re: script to encrypt messages, please

Posted: 02 May 2011 17:35
by tiago
I'll try that, thanks!

Re: script to encrypt messages, please

Posted: 14 May 2011 17:10
by tiago
No go so far. If anyone has a working build for this request please let me know.

Re: script to encrypt messages, please

Posted: 14 May 2011 17:28
by Stefan
If i had an glue what you want :roll:

Give a few examples please:

You have this file names:
1
2
3

And after they should look like:
1
2
3


.

Re: script to encrypt messages, please

Posted: 14 May 2011 20:08
by tiago
Hello, Stefan! :)

I just want something to replacelist() based off of a seed, commonly shared among source and destination users which will encrypt/decrypt a message. It's pretty similar to what your Rot13 link does, except that it has a random seed to generate an encryption/decryption key. Clear...?
Thanks in advance.

Re: script to encrypt messages, please

Posted: 14 May 2011 22:17
by Stefan
You want to encrypt messages? Like

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.
Tabbed Browsing. Cutting-edge file management using a true multi-tabbed interface.
The optional Dual Pane mode spells productivity and ease of use, especially for those coming from an orthodox file manager. Learn more...
Multi-Level Undo/Redo for file operations, stored between sessions, allows you to fix today what you broke yesterday. Learn more...
Queued File Operations with background processing. Enjoy the speed and safety of a Copy Queue. Learn more...
Powerful File Search with amazing speed. It supports Boolean Logic, Regular Expressions, Boolean RegExp, Content Search, and more...
Tag-Based File Management supports assigning individual labels, tags, and comments to any file and folder. More...


TO encrypt:

Jlggfikvu Fgvirkzex Jpjkvdj: Nzeufnj 0, 5331, Mzjkr, OG, 5336, 5333, EK, Dv, 21. Sfky 65-szk reu 97-szk mvijzfej, nyviv rggcztrscv, riv jlggfikvu.
OPgcfivi zj r Gfikrscv Wzcv Drerxvi. Zk ufvje'k ivhlziv rep zejkrccrkzfe fi tyrexvj kf pfli jpjkvd fi ivxzjkip. Jkztbnriv, zuvrc wfi r LJS uizmv.
Krssvu Sifnjzex. Tlkkzex-vuxv wzcv drerxvdvek ljzex r kilv dlckz-krssvu zekviwrtv.
Kyv fgkzferc Ulrc Grev dfuv jgvccj gifultkzmzkp reu vrjv fw ljv, vjgvtzrccp wfi kyfjv tfdzex wifd re fikyfufo wzcv drerxvi. Cvrie dfiv...
Dlckz-Cvmvc Leuf/Ivuf wfi wzcv fgvirkzfej, jkfivu svknvve jvjjzfej, rccfnj pfl kf wzo kfurp nyrk pfl sifbv pvjkviurp. Cvrie dfiv...
Hlvlvu Wzcv Fgvirkzfej nzky srtbxifleu giftvjjzex. Veafp kyv jgvvu reu jrwvkp fw r Tfgp Hlvlv. Cvrie dfiv...
Gfnviwlc Wzcv Jvrity nzky rdrqzex jgvvu. Zk jlggfikj Sffcvre Cfxzt, Ivxlcri Vogivjjzfej, Sffcvre IvxVog, Tfekvek Jvrity, reu dfiv...
Krx-Srjvu Wzcv Drerxvdvek jlggfikj rjjzxezex zeuzmzulrc crsvcj, krxj, reu tfddvekj kf rep wzcv reu wfcuvi. Dfiv...


And back to decrypt:

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.
Tabbed Browsing. Cutting-edge file management using a true multi-tabbed interface.
The optional Dual Pane mode spells productivity and ease of use, especially for those coming from an orthodox file manager. Learn more...
Multi-Level Undo/Redo for file operations, stored between sessions, allows you to fix today what you broke yesterday. Learn more...
Queued File Operations with background processing. Enjoy the speed and safety of a Copy Queue. Learn more...
Powerful File Search with amazing speed. It supports Boolean Logic, Regular Expressions, Boolean RegExp, Content Search, and more...
Tag-Based File Management supports assigning individual labels, tags, and comments to any file and folder. More...


USE:

Code: Select all

//XYplorer script to encrypt small piece of text by simply shifting chars along the ascii table.
//Use   "$salt = 17;"  (number between 1 and 25 ONLY) for encrypt and decrypt key.
//Take an look at an ASCII Table to see how it works: http://web.cs.mun.ca/~michael/c/ascii-table.html

"encrypt" 
  $string = "<clipboard>";
  $salt = 17; // between 1 and 25 ONLY
  $out="";
  $count = 0;
   while(1){
     $char = substr($string, $count, 1);
     If ($char==""){
         break;}
     else{
         $asc = asc("$char");
         IF ($asc >= 65  && $asc <= 90 ){
            $ascnew = $asc + $salt;
            IF ($ascnew > 90){$ascnew = $ascnew - 26;}
            $char = chr($ascnew);}
         elseIF ($asc >= 97  && $asc <= 122 ){
            $ascnew = $asc + $salt;
            IF ($ascnew > 122){$ascnew = $ascnew - 26;}
            $char = chr($ascnew);}
         elseIF ($asc >= 48  && $asc <= 57 ){
            $ascnew = $asc + 3;
            IF ($ascnew > 57){$ascnew = $ascnew - 10;}
            $char = chr($ascnew);}
         else{$char=$char;}
     }
     $out = $out$char;
     incr $count;
   }
   text $out;

"decrypt"
  $string = "<clipboard>";
  $salt = 17; // between 1 and 25 ONLY
  $out="";
  $count = 0;
   while(1){
     $char = substr($string, $count, 1);
     If ($char==""){
        break;}
     else{
         $asc = asc("$char");
         IF ($asc >= 65  && $asc <= 90 ){
            $ascnew = $asc - $salt;
            IF ($ascnew < 65){$ascnew = $ascnew + 26;}
            $char = chr($ascnew);}
         elseIF ($asc >= 97  && $asc <= 122 ){
            $ascnew = $asc - $salt;
            IF ($ascnew < 97){$ascnew = $ascnew + 26;}
            $char = chr($ascnew);}
         elseIF ($asc >= 48  && $asc <= 57 ){
            $ascnew = $asc - 3;
            IF ($ascnew < 48){$ascnew = $ascnew + 10;}
            $char = chr($ascnew);}
         else{$char=$char;}
     }
     $out = $out$char;
     incr $count;
   }
   text $out;
Works with first tests. I don't know if it is really good. Just try it.
Script takes some second to run so use only for smaller piece of text.

Re: script to encrypt messages, please

Posted: 15 May 2011 09:51
by admin
In the next version you can try this:

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>";
  $seed = input("Enter Seed<crlf>The same seed has to be used for encryption and decryption.", "Can be any number apart from 0." , "17");
  $chars = ' .,;:!?*"#_-+()<>[]{}/\=$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  $charsrnd = formatlist($chars, "cx", "", $seed);

Re: script to encrypt messages, please

Posted: 15 May 2011 16:23
by tiago
Stefan: great idea. I just can't see a share-able key to distribute to receiver, am I missing something...?

Don: thank you for taking this seriously. Great: I can use any number like "1654" and some nebulous part of my brain told me to test 1...42 (26 letters + 10 numbers + some extra effort just in case) as a brute force method (it's complicated to explain, but I thought the seed could be reduced to the number of components in a...Z plus 0...9... and it can't! So a person really needs to know the exact seed to decrypt a message). But using loops I easily broke the decryption method... The idea is to have a seed/en-decryption key like "aTmexpbzyJK98R4nFZuWdwclV6vA2StDHQf5OrC3oiEs1LUXI0GgPBj7qhkMNY" (Stefan wrote a great seed generator which I used in my attempts to get this done), used au pair with replacelist and I'm still stuck with this.

Oh yes, $chars has a role on this, but I bet it can be hacked since the script uses sorting as a part of its mechanics.

Thank you guys!

Re: script to encrypt messages, please

Posted: 15 May 2011 16:49
by admin
tiago wrote:But using loops I easily broke the decryption method...
How? Letter frequency analysis?

Re: script to encrypt messages, please

Posted: 15 May 2011 17:05
by tiago
admin wrote:
tiago wrote:But using loops I easily broke the decryption method...
How? Letter frequency analysis?
Easier. Will pm you the script.

Re: script to encrypt messages, please

Posted: 15 May 2011 17:21
by admin
tiago wrote:
admin wrote:
tiago wrote:But using loops I easily broke the decryption method...
How? Letter frequency analysis?
Easier. Will pm you the script.
OK, but when seed is a large number this can take very long...

Re: script to encrypt messages, please

Posted: 15 May 2011 17:42
by tiago
admin wrote:
tiago wrote:
admin wrote:
tiago wrote:But using loops I easily broke the decryption method...
How? Letter frequency analysis?
Easier. Will pm you the script.
OK, but when seed is a large number this can take very long...
Nearly impossible if the seed is alphanumeric. :hint: