Author Topic: Encrypt symbol names (snvalid)  (Read 298 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Encrypt symbol names (snvalid)
« on: November 26, 2017, 04:07:07 pm »

From this topic: https://www.theswamp.org/index.php?topic=34893.0 is there a function to encrypt
by getting a string that respects snvalid?
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

Grrr1337

  • Bull Frog
  • Posts: 453
Re: Encrypt symbol names (snvalid)
« Reply #1 on: November 26, 2017, 04:48:49 pm »
You could wrap someone's encryptive function like:
Code: [Select]
(defun SnvalidEncryptWrapping ( str EncryptFoo )
  (if (snvalid str)
    (EncryptFoo str)
    (prompt "\nString not valid to be encrypted.")
  )
)
Same with the decriptive function.




That thread is very interesting, to not bump it heres something simple I wrote:
Code - Auto/Visual Lisp: [Select]
  1. ; _$ (decrypt (encrypt "Hello World, my password is..." nil) nil)
  2. ; "Hello World, my password is..."
  3. ; ipw - Integer password, affects speed, so use value up to 8 or 9
  4. ; (decrypt (encrypt "Hello World" 9) 9)
  5. (defun encrypt (s ipw)
  6.  (setq s (vl-string->list s))
  7.  (repeat (cond (ipw)(5))
  8.    (setq s (vl-string->list (vl-prin1-to-string s)))
  9.  )
  10.  s
  11. )
  12.  
  13. (defun decrypt (s ipw)
  14.  (repeat (1+ (cond (ipw)(5)))
  15.    (setq s (vl-list->string (read s)))
  16.  )
  17.  s
  18. )

...and I guess this modification matches your requirements:
Code - Auto/Visual Lisp: [Select]
  1. (defun encrypt ( s / r )
  2.  (and (snvalid s) (setq s (vl-string->list s))
  3.    (progn (repeat 5 (setq s (vl-string->list (vl-prin1-to-string s)))) (setq r s))
  4.  )
  5.  r
  6. )
  7.  
  8. (defun decrypt ( s / r )
  9.  (and
  10.    (setq s (vl-prin1-to-string s))
  11.    (progn (repeat 6 (setq s (vl-list->string (read s)))) (snvalid s))
  12.    (setq r s)
  13.  )
  14.  r
  15. )

Code - Auto/Visual Lisp: [Select]
  1. _$ (snvalid "Hello World, my password is...") -> nil
  2. _$ (snvalid "Hello World my password is") -> T
  3.  
  4. _$ (decrypt (encrypt "Hello World, my password is...")) -> nil
  5. _$ (decrypt (encrypt "Hello World my password is")) -> "Hello World my password is"
  6.  


But with such simple modification you could use it on anyone else's code there [ starting with (snvalid str) check ].
« Last Edit: November 26, 2017, 05:24:33 pm by Grrr1337 »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Encrypt symbol names (snvalid)
« Reply #2 on: November 27, 2017, 08:41:59 am »

Thank you for your effort, maybe I did not explain it well (as usual, apologize for my English): I asked if there is a function that encrypt symbol names by returning a valid symbol name for snvalid.

Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

MP

  • Seagull
  • Posts: 17015
  • brevity != aggression
Re: Encrypt symbol names (snvalid)
« Reply #3 on: November 27, 2017, 11:03:29 am »
How strong does it need to be?
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Encrypt symbol names (snvalid)
« Reply #4 on: November 27, 2017, 11:19:09 am »
How strong does it need to be?
Very soft...
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

MP

  • Seagull
  • Posts: 17015
  • brevity != aggression
Re: Encrypt symbol names (snvalid)
« Reply #5 on: November 27, 2017, 11:34:28 am »
You could use flavors of classic (weak) ROT13 obfuscation.

Code: [Select]
(defun _RotateTextByMap ( text textmap / n codes )

    ;;  Caller's job to ensure textmap is of even length!!

    (setq
        n     (/ (strlen textmap) 2)
        codes (vl-string->list textmap)
        codes (append codes codes)
    )

    (vl-list->string
        (mapcar
            (function
                (lambda ( x / lst )
                    (if (setq lst (member x codes))
                        (nth n lst)
                        x
                    )
                )
            )
            (vl-string->list text)
        )
    )

)

Code: [Select]
(defun _Rot13 ( text )

    ;;  See: http://en.wikipedia.org/wiki/ROT13
    ;;
    ;;  Basically does a safe text rotation. If rotated twice
    ;;  returns the original string. Very simple obfuscation
    ;;  to thwart casual browsing by uninitiated eyes.
    ;;
    ;;  NOTE: FORCES UPPERCASE
    ;;
    ;;  (_Rot13 "abc ABC xyz XYZ 012 789") >> "ONP ONP KLM KLM 012 789"
    ;;  (_Rot13 "567 fgh STU 234 VWX cde") >> "ABC ABC XYZ XYZ 012 789"

    (_RotateTextByMap
        (strcase text)
        "ABCDEFGHIJKLMONPQRSTUVWXYZ"
    )

)

Code: [Select]
(defun _Rot31 ( text )

    ;;  (_Rot31 "abc ABC xyz XYZ 012 789") >> "567 fgh STU 234 VWX cde"
    ;;  (_Rot31 "567 fgh STU 234 VWX cde") >> "abc ABC xyz XYZ 012 789"

    (_RotateTextByMap
        text
        (strcat
            "0123456789"
            "ABCDEFGHIJKLMONPQRSTUVWXYZ"
            "abcdefghijklmonpqrstuvwxyz"
        )
    )

)
   

Code: [Select]
(defun _Rot40 ( text )

    ;;  (_Rot40 "abc ABC xyz XYZ 012 789") >> "123 klm NOP $%& _ab ghi"
    ;;  (_Rot40 "123 klm NOP $%& _ab ghi") >> "abc ABC xyz XYZ 012 789"

    (_RotateTextByMap
        text
        (strcat
            "!#$%&()-0123456789@ABCDEFGHIJKLMNOPQRSTU"
            "VWXYZ[]^_abcdefghijklmnopqrstuvwxyz{}~"
        )
    )

)
   

Cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Encrypt symbol names (snvalid)
« Reply #6 on: November 27, 2017, 12:31:58 pm »
Thanks Michael, _Rot40 is better to preserve also the case:  (_Rot40 (_Rot40 "$Foo_02-B_01")) > "$Foo_02-B_01"
In Bricscad I have this behaviour of snvalid (in AutoCAD all are ok):
Code: [Select]
(defun testsnvalid (str / Countr Caract)
  (setq Countr 1)
  (repeat (strlen str)
    (if (snvalid (setq Caract (substr str Countr 1)))
      (princ Caract)
      (progn (print Caract) (princ " < NOT valid - Valid >    "))
    )
    (setq Countr (1+ Countr))
  )
  (princ)
)
Code: [Select]
(testsnvalid "!#$%&()-0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{}~")
"!"  < NOT valid - Valid >    #$%&()-0123456789
"@"  < NOT valid - Valid >    ABCDEFGHIJKLMNOPQRSTUVWXYZ
"["  < NOT valid - Valid >   
"]"  < NOT valid - Valid >    ^_abcdefghijklmnopqrstuvwxyz
"{"  < NOT valid - Valid >   
"}"  < NOT valid - Valid >    ~
May I use this version also for Bricscad?
Code: [Select]
(defun _Rot40 ( text )
    (_RotateTextByMap
        text
        (strcat
           ;"!#$%&()-0123456789@ABCDEFGHIJKLMNOPQRSTU"
            "#$%&()-0123456789ABCDEFGHIJKLMNOPQRSTU"
           ;"VWXYZ[]^_abcdefghijklmnopqrstuvwxyz{}~"
            "VWXYZ^_abcdefghijklmnopqrstuvwxyz~"
        )
    )
)
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

MP

  • Seagull
  • Posts: 17015
  • brevity != aggression
Re: Encrypt symbol names (snvalid)
« Reply #7 on: November 27, 2017, 12:40:59 pm »
Technically it would be Rot37. I don't have Brics so can't help (notwithstanding, no play time avail).
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Encrypt symbol names (snvalid)
« Reply #8 on: November 27, 2017, 12:51:06 pm »
Technically it would be Rot37. I don't have Brics so can't help (notwithstanding, no play time avail).
Ok grazie.  :)
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

MP

  • Seagull
  • Posts: 17015
  • brevity != aggression
Re: Encrypt symbol names (snvalid)
« Reply #9 on: November 27, 2017, 03:14:50 pm »
Wrote a quick & dirty func over lunch ...

Code: [Select]
(defun _Obfus ( text mask )

    ;;  (setq
    ;;      text  "MyCollectionName"
    ;;      mask1 ""
    ;;      mask2 "wat"
    ;;      mask3 "HHGTTG"
    ;;  )
    ;; 
    ;;  (_Obfus text mask1)               >> "EyDjolljtjjiHiec"
    ;;  (_Obfus "EyDjolljtjjiHiec" mask1) >> "MyCollectionName"
    ;;
    ;;  (_Obfus text mask2)               >> "MFCoS90c&iPnN^m7"
    ;;  (_Obfus "MFCoS90c&iPnN^m7" mask2) >> "MyCollectionName"
    ;;
    ;;  (_Obfus text mask3)               >> "k_fo^IeQFLIHhGHW"
    ;;  (_Obfus "k_fo^IeQFLIHhGHW" mask3) >> "MyCollectionName"
   
    (   (lambda ( a b ok n )
            (while (< (length b) n) (setq b (append b (reverse b))))
            (vl-list->string
                (mapcar
                    (function
                        (lambda ( a b / x )
                            (if (and (member a ok) (member (setq x (boole 6 a b)) ok))
                                x
                                a
                            )
                        )
                    )
                    a
                    b
                )
            )
        )
        (vl-string->list text)
        (cond ((mapcar (function (lambda (x) (- x 34))) (vl-string->list mask))) ('(8 6 7 5 3 0 9)))
        (vl-string->list "#$%&()-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_abcdefghijklmnopqrstuvwxyz~")
        (strlen text)
    )
)

Cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Encrypt symbol names (snvalid)
« Reply #10 on: November 27, 2017, 03:26:36 pm »

Wrote a quick & dirty func over lunch ...
Cheers.
Grande, I think this is quite enough.  :) :) :)
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

gile

  • Water Moccasin
  • Posts: 2095
  • Marseille, France
Re: Encrypt symbol names (snvalid)
« Reply #11 on: November 29, 2017, 03:42:06 am »
Hi,

This remember me this other thread.
Speaking English as a French Frog

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Encrypt symbol names (snvalid)
« Reply #12 on: November 29, 2017, 04:05:41 am »


Hi,

This remember me this other thread.
thanks to gile, it's too technical thread for me...  :?
right for curiosity (Michael's function is great for my need), without trying to test all the functions, is there in that thread any one that respects snvalid?
(I need to "Obfus" i.e. blocks names)
Grazie.  :)
« Last Edit: November 29, 2017, 04:15:50 am by Marc'Antonio Alessi »
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega