Author Topic: (Challenge) Encrypt and decipher the text.  (Read 11161 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
(Challenge) Encrypt and decipher the text.
« on: September 14, 2010, 03:38:16 AM »
In this topic, I propose to compete in the encryption and decryption of text. You can use any algorithms, but there is one condition, you must create a program for encryption and decryption. The text after decryption should just repeat the original.

Code: [Select]
(setq s "(alert \"Hello, world!\")")

(encrypt s) =>> incomprehensible information (text, numbers, lists ...)

(decrypt(encrypt s)) =>> "(alert \"Hello, world!\")"
« Last Edit: September 14, 2010, 04:23:32 AM by ElpanovEvgeniy »

Patrick_35

  • Guest
Re: (Challenge) Encrypt and decipher the text.
« Reply #1 on: September 14, 2010, 04:29:41 AM »
A subroutine which dates back to version 14.
Always topical  8-)

Code: [Select]
(decrypt (encrypt "long life theswamps"))
@+

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Encrypt and decipher the text.
« Reply #2 on: September 14, 2010, 04:45:34 AM »
Explain why the code after compilation?
You can not show the algorithm?
In this topic, I propose to share ideas and algorithms, to learn from friends ...

Patrick_35

  • Guest
Re: (Challenge) Encrypt and decipher the text.
« Reply #3 on: September 14, 2010, 05:04:10 AM »
Explain why the code after compilation?
You can not show the algorithm?
In this topic, I propose to share ideas and algorithms, to learn from friends ...
As this is to encrypt / decrypt a code, I voluntarily compiled lisp (which is very rare for me).

Now, I am willing to distribute the code, but in private, because if I do a broadcast, it is nothing more to encode anything

You can also try to break the code

@+

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: (Challenge) Encrypt and decipher the text.
« Reply #4 on: September 14, 2010, 05:14:12 AM »
How about this:

Code: [Select]
(defun NumCryptWithKey (numLst numKey operand / useKey)
  (setq useKey numKey)
  (mapcar
    '(lambda (a / b)
      (setq b (car useKey))
      (setq useKey (cond ((cdr useKey)) (numKey)))
      (operand a b)
    )
    numLst
  )
)

(defun Encrypt (str)
  (NumCryptWithKey (vl-string->list str) '(8 5 13 12 99 3) +)
)

(defun Decrypt (numLst)
  (vl-list->string (NumCryptWithKey numLst '(8 5 13 12 99 3) -))
)

; (Encrypt "(alert \"Hello, world!\")") => (48 102 121 113 213 119 40 39 85 113 207 111 119 49 45 131 210 117 116 105 46 46 140)
; (Decrypt (Encrypt "(alert \"Hello, world!\")")) => "(alert \"Hello, world!\")"

While working on this I stumbled on something strange:
(ascii "ƒ") =>  131
(vl-string->list "ƒ") => (402)
Is this a bug in Bricscad?

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Encrypt and decipher the text.
« Reply #5 on: September 14, 2010, 05:17:06 AM »
While working on this I stumbled on something strange:
(ascii "ƒ") =>  131
(vl-string->list "ƒ") => (402)
Is this a bug in Bricscad?

AutoCAD 2011:
(ascii "?") =>  63
(vl-string->list "?") => (63)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Encrypt and decipher the text.
« Reply #6 on: September 14, 2010, 05:21:53 AM »
How about this:

Code: [Select]
(defun NumCryptWithKey (numLst numKey operand / useKey)
  (setq useKey numKey)
  (mapcar
    '(lambda (a / b)
      (setq b (car useKey))
      (setq useKey (cond ((cdr useKey)) (numKey)))
      (operand a b)
    )
    numLst
  )
)

(defun Encrypt (str)
  (NumCryptWithKey (vl-string->list str) '(8 5 13 12 99 3) +)
)

(defun Decrypt (numLst)
  (vl-list->string (NumCryptWithKey numLst '(8 5 13 12 99 3) -))
)

; (Encrypt "(alert \"Hello, world!\")") => (48 102 121 113 213 119 40 39 85 113 207 111 119 49 45 131 210 117 116 105 46 46 140)
; (Decrypt (Encrypt "(alert \"Hello, world!\")")) => "(alert \"Hello, world!\")"


Good idea, the program uses the key, you can use different keys for different purposes...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Encrypt and decipher the text.
« Reply #7 on: September 14, 2010, 05:24:39 AM »
As this is to encrypt / decrypt a code, I voluntarily compiled lisp (which is very rare for me).

Now, I am willing to distribute the code, but in private, because if I do a broadcast, it is nothing more to encode anything

You can also try to break the code

@+

I appreciate your code and your protection!
For fun, I propose to write new code, just for this topic ...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: (Challenge) Encrypt and decipher the text.
« Reply #8 on: September 14, 2010, 05:30:11 AM »
AutoCAD 2011:
(ascii "?") =>  63
(vl-string->list "?") => (63)
What do you get with this:
(chr 131) => "ƒ"

Patrick_35

  • Guest
Re: (Challenge) Encrypt and decipher the text.
« Reply #9 on: September 14, 2010, 05:31:20 AM »
Ok

A simple

Code: [Select]
(defun encrypt(txt)
  (vl-list->string (mapcar '(lambda(x) (boole 6 x 13)) (vl-string->list txt)))
)

(encrypt (encrypt "long life theswamps"))

@+

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Encrypt and decipher the text.
« Reply #10 on: September 14, 2010, 05:32:30 AM »
AutoCAD 2011:
(ascii "?") =>  63
(vl-string->list "?") => (63)
What do you get with this:
(chr 131) => "ƒ"

(chr 131) => "ƒ"

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) Encrypt and decipher the text.
« Reply #12 on: September 14, 2010, 05:59:26 AM »
How about this:
< snip>


nice functionality Roy.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE3

  • Guest
Re: (Challenge) Encrypt and decipher the text.
« Reply #13 on: September 14, 2010, 10:41:20 AM »
Something I wrote 17 years ago.... geezzzz you guys are old!  :laugh:

http://www.theswamp.org/index.php?topic=9441.msg121482#msg121482

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: (Challenge) Encrypt and decipher the text.
« Reply #14 on: September 14, 2010, 10:45:17 AM »
Wish I had time for more posting than just the concept... it was intended for use with LSP files, so there was no need to handle extended ASCII characters.  I made a simple substitution cypher (including line breaks) called "NCRYPT", then re-sequenced the output so each line had a fixed number of characters.  The file also included an header with decryption instructions, including the proper decryption cypher file, the option for a kill date, permissible user names, and permissible computer names.  The decryption routine "DCRYPT" made use of a separate file with the decryption substitution matrix itself encoded and fixed-line lengths.  The one module I did prototype was for a straight to-file function, while I outlined another for decrypting to a temp file including a (load...) call, and another that would have the encrypted file as self-contained with the decryption matrix included in the header.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: (Challenge) Encrypt and decipher the text.
« Reply #15 on: September 14, 2010, 02:02:39 PM »
Code: [Select]
(defun encrypt (s)
  (setq s (vl-string->list s))
  (vl-list->string
    (mapcar (function (lambda (c1 c2) (boole 6 c1 c2))) s (cons (length s) s))
  )
)
(defun decrypt (s / x)
  (setq x (strlen s))
  (vl-list->string
    (mapcar (function (lambda (c) (setq x (boole 6 c x)))) (vl-string->list s))
  )
)
although it does not satisfy the requirements

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Encrypt and decipher the text.
« Reply #16 on: September 14, 2010, 02:22:28 PM »
Code: [Select]
(defun encrypt (s)
  (setq s (vl-string->list s))
  (vl-list->string
    (mapcar (function (lambda (c1 c2) (boole 6 c1 c2))) s (cons (length s) s))
  )
)
(defun decrypt (s / x)
  (setq x (strlen s))
  (vl-list->string
    (mapcar (function (lambda (c) (setq x (boole 6 c x)))) (vl-string->list s))
  )
)

Hello VovKa!
Interesting idea to use the length of the string in the boole transformation.

although it does not satisfy the requirements

I do not understand why?

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: (Challenge) Encrypt and decipher the text.
« Reply #17 on: September 14, 2010, 02:56:10 PM »
I do not understand why?
oops, i am wrong. i've reread your first post and now i see that my code is ok.
i thought is was (encrypt(encrypt s)) =>> "(alert \"Hello, world!\")"

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: (Challenge) Encrypt and decipher the text.
« Reply #18 on: September 14, 2010, 04:17:12 PM »
How about a base conversion:

Code: [Select]
(defun LM:toBase ( str from to / -> <- )
  ;; © Lee Mac 2010

  (defun -> ( n / b x )
    (if (<= to n)
      (strcat (-> (/ n to)) (-> (rem n to)))
      (chr (+ n (if (< n 10) 48 55)))
    )
  )

  (defun <- ( l )
    (if l (+ (* from (<- (cdr l))) (car l)) 0)
  )

  (-> (<- (mapcar '(lambda ( x ) (- x (if (< x 58) 48 55))) (reverse (vl-string->list str)))))
)

(defun LM:Encrypt ( x )
  (mapcar '(lambda ( c ) (LM:toBase (itoa c) 10 2)) (vl-string->list x))
)

(defun LM:Decrypt ( x )
  (vl-list->string (mapcar '(lambda ( c ) (atoi (LM:toBase c 2 10))) x))
)

;; (LM:Decrypt (LM:Encrypt "Long Live theSwamp"))

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: (Challenge) Encrypt and decipher the text.
« Reply #19 on: September 15, 2010, 05:45:58 AM »
How about a base conversion:
Nice coding, but in terms of encryption your solution is like leaving your key on the doormat. :wink:

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: (Challenge) Encrypt and decipher the text.
« Reply #20 on: September 15, 2010, 02:31:25 PM »
How about a base conversion:
Nice coding, but in terms of encryption your solution is like leaving your key on the doormat. :wink:

Of course - could be hacked pretty easily  :-)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (Challenge) Encrypt and decipher the text.
« Reply #21 on: September 15, 2010, 03:30:52 PM »
Quick and dirty mild obfuscation code is mildly obfuscated:

Code: [Select]
(defun obfuscate ( text mask )
    (   (lambda ( a b c d e ) (vl-list->string (cdr (mapcar 'd a (e b (length a))))))
        (cons 48 (vl-string->list text))
        (cons 64 (vl-string->list mask))
        (rem (+ 96 (strlen text) (strlen mask)) 255)
        (lambda (a b) (boole 6 c (boole 6 a b)))
        (lambda (a b) (while (< (length a) b) (setq a (append a (reverse a)))) a)
    )
)

(setq
    text "It hung in the air in exactly the same way  that bricks don't."
    mask "Trillian's mice."
)

(obfuscate text mask)
>> "³¨çª·©¨àà³®·¯¨ëáé¹í®­®¸ñ¡¬³®»ç¨’‹Î‰½ª§â°®¹©ýú«¦¹ëâò¢®¬°®¹æ®è³ì"

(obfuscate (obfuscate text mask) mask)
>> "It hung in the air in exactly the same way  that bricks don't."
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

danallen

  • Guest
Re: (Challenge) Encrypt and decipher the text.
« Reply #22 on: September 15, 2010, 10:25:46 PM »
one time pad concept?

(setq s "(alert \"Hello, world!\")")
"(alert \"Hello, world!\")"

(ABC_EncryptStr255 s)
"\016\024§-”Ú¨$\0278õЈþòÔðPŒ½©)\016"

(ABC_DecryptStr255 (ABC_EncryptStr255 s))
"(alert \"Hello, world!\")"


past resource http://groups.google.com/group/autodesk.autocad.customization/browse_thread/thread/440f8e32ef9d534d/217e31e1a5e91c82

Code: [Select]
;;;=========================================================================
;;; Encrypt a string with a base 255 ABC Cypher (defined below)
;;;=========================================================================
(defun ABC_EncryptStr255 (str / StrListDec CypherCode NewListDec NewStr)
  (if *ABC-Cypher255*
    (progn
      (setq StrListDec    (vl-string->list str) ;convert string to list of ascii codes
            CypherCode    (ABC_SubList (*ABC-Cypher255* "CAVEman") 1 (strlen str)) ;get cypher in length of string to be encoded
            ;; cypher string
            NewListDec (mapcar '(lambda (x y) (ABC_IntShiftBaseUp x y 255)) StrListDec CypherCode)
            NewStr     (vl-list->string NewListDec) ;convert cyphered codes back to ascii
      )
    )
  )
)

;;;=========================================================================
;;; Decrypt a string with a base 255 ABC Cypher
;;;=========================================================================
(defun ABC_DecryptStr255 (str / StrListDec CypherCode NewListDec NewStr)
  (if *ABC-Cypher255*
    (progn
      (setq StrListDec    (vl-string->list str) ;convert string to list of ascii codes
            CypherCode    (ABC_SubList (*ABC-Cypher255* "CAVEman") 1 (strlen str)) ;get cypher in length of string to be encoded
            ;; cypher string
            NewListDec (mapcar '(lambda (x y) (ABC_IntShiftBaseDown x y 255)) StrListDec CypherCode)
            NewStr     (vl-list->string NewListDec) ;convert cyphered codes back to ascii
      )
    )
  )
)

;;;=========================================================================
;;; 1000 character long cypher - base 255
;;; Cypher definition needs to be protected from listing
;;; Use (*ABC-Cypher255* "CAVEman") to return list
;;; Be sure to declare as local
;;;=========================================================================
(defun *ABC-Cypher255* (password)
  (if (= password "CAVEman")
       (list 229  178  59   199  34   102  136  2    206  210  137  100  25   210  210  93   129  221  32   89   136
             7    228  152  226  34   231  47   204  212  130  180  208  2    116  178  161  97   187  141  78   128
             105  209  130  50   1    166  10   165  50   98   88   253  146  227  64   209  38   198  151  100  77
             19   7    228  2    108  178  150  217  107  244  70   206  50   241  195  60   213  35   215  23   171
             172  125  194  38   155  185  144  65   222  237  86   43   26   246  19   53   31   244  38   164  54
             17   251  134  247  33   187  16   233  111  232  179  154  146  99   102  118  162  217  92   253  166
             256  161  175  145  177  199  74   161  60   58   160  136  16   68   188  34   16   119  143  33   153
             109  210  127  186  159  105  14   136  74   233  1    9    13   137  197  185  85   48   254  12   36
             217  9    2    93   2    211  34   31   97   90   246  73   154  193  103  199  40   57   255  183  47
             168  133  4    125  90   227  136  98   161  227  84   159  171  158  56   33   120  50   23   195  61
             162  43   210  9    95   201  123  21   121  200  243  123  223  16   124  210  192  129  13   90   97
             178  200  58   137  181  10   143  216  103  50   166  24   114  240  68   242  139  69   74   5    23
             244  148  222  180  143  99   181  219  242  47   129  31   66   63   65   43   71   206  5    13   65
             43   173  242  3    148  197  234  129  61   142  184  133  68   156  105  213  254  4    166  109  96
             151  116  19   246  27   107  248  33   2    255  155  22   139  251  179  84   215  185  63   6    213
             55   148  20   142  163  134  75   194  109  113  101  75   129  89   86   69   187  214  174  110  44
             6    109  182  81   61   25   127  198  169  120  115  152  165  197  130  205  241  170  224  50   136
             235  162  15   73   13   196  219  50   210  66   123  93   235  9    51   122  172  106  213  2    30
             219  87   214  81   154  74   128  52   38   109  214  220  244  223  50   129  118  4    245  34   206
             203  147  5    56   85   215  17   160  164  164  57   85   102  220  232  85   115  177  185  49   18
             21   84   245  169  121  209  16   229  160  107  187  242  181  231  206  229  93   131  127  230  256
             195  2    50   3    244  133  155  29   193  123  136  153  173  175  30   157  211  32   165  76   178
             10   191  231  116  47   138  170  118  189  72   161  112  221  159  48   22   88   15   116  139  82
             179  76   117  133  231  51   21   10   229  170  53   19   249  101  74   150  97   244  149  105  112
             40   168  182  7    225  40   83   15   125  17   221  236  177  115  48   165  233  220  13   188  3
             105  134  94   130  189  22   256  11   194  233  249  80   143  56   64   42   57   80   214  25   3
             29   4    227  167  196  239  134  40   62   185  55   251  107  165  170  215  156  116  86   25   251
             121  233  254  227  148  184  148  134  153  63   200  233  69   150  71   171  87   231  175  138  228
             192  208  36   125  99   95   233  67   211  238  183  124  223  135  17   199  208  186  128  128  256
             129  240  113  20   195  167  102  3    222  183  190  175  5    104  140  70   207  155  106  26   203
             137  134  51   117  244  21   79   100  35   175  131  6    185  193  64   194  210  156  230  219  97
             61   172  240  73   114  9    93   36   96   90   116  58   22   255  202  148  49   170  131  171  64
             9    231  164  232  149  35   160  114  183  134  256  210  249  29   46   196  119  244  207  18   89
             227  231  158  118  64   212  72   239  65   172  71   233  109  233  15   38   253  218  88   181  116
             223  99   110  83   215  18   116  56   193  230  118  76   7    140  224  74   108  252  193  254  20
             205  146  151  150  215  157  160  163  183  52   244  37   82   124  142  94   225  253  134  244  185
             169  27   104  69   160  17   239  106  94   83   38   214  142  30   148  90   63   147  117  241  163
             11   207  117  45   2    51   178  36   242  60   225  127  242  48   37   47   120  197  38   154  19
             128  92   124  114  161  43   229  149  35   93   136  120  178  28   33   31   30   250  23   72   69
             44   34   172  223  130  33   24   49   58   228  69   20   82   21   187  86   82   3    156  216  76
             128  176  124  15   145  136  63   40   24   13   145  224  78   93   74   166  30   69   74   44   63
             44   49   162  39   218  33   81   163  217  21   8    67   227  178  141  78   27   16   164  133  123
             125  186  91   80   160  216  233  7    4    245  72   64   122  48   154  102  74   35   105  179  182
             208  156  247  177  78   193  237  96   203  208  137  59   239  57   8    103  85   91   35   39   11
             53   51   235  214  112  175  241  56   143  200  236  221  116  136  176  131  235  75   88   244  134
             225  216  46   109  64   127  79   103  16   85   88   211  238  218  102  191  191  12   123  233  240
             66   97   199  239  187  210  101  186  121  110  75   232  54   157  23   236  28   246  22   3    7
             65   133  145  242  172  184  85   108  76   226  59   154  131
            ) ;_ list
    )
) ;_ setq

;;;==========================================================
;;; Function : Returns only a part of a list, works like SUBSTR
;;; Argument : [ Lst ]  - List to check
;;;            [ Start] - starting position, starts from 1
;;;            [  len ] - Number of elements to extract
;;;                       If len is negative, returns until the end of the list
;;; Return   : The extracted list
;;; Updated  : December18, 1998
;;; Copyright: (C) 2000, Four Dimension Technologies, Singapore
;;; Contact  : rakesh.rao@4d-technologies.com for help/support/info
;;;==========================================================
(defun ABC_SubList (Lst Start len / _len n m _Lst)
  (if (minusp len)
    (setq len 999999999)
  ) ;_ if
  (setq _len (length Lst)
        n    (min (- Start 1) _len)                                             ; Starting Index
        m    (min (+ n len) _len)                                               ; Ending Index
        _Lst '()
  ) ;_ setq
  (while (< n m)
    (setq _Lst (cons (nth n Lst) _Lst)
          n    (1+ n)
    ) ;_ setq
  ) ;_ while
  (reverse _Lst)
) ;_ defun

;;;=========================================================================
;;; simple shift up of one decimal number by another on a base of 255 (hexidecimal)
;;; used for simple encoding of one number by another
;;;=========================================================================
(defun ABC_IntShiftBaseUp (a b base / c)
  (setq c (+ a b))
  (if (> c base)
    (setq c (- c base))
    c
  )
)

;;;=========================================================================
;;; simple shift down of one decimal number by another on a base of 255 (hexidecimal)
;;; used for simple decoding of one number by another
;;;=========================================================================
(defun ABC_IntShiftBaseDown (a b base / c)
  (setq c (- a b))
  (if (< c 0)
    (setq c (+ c base))
    c
  )
)