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

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • 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?

Grrr1337

  • Swamp Rat
  • Posts: 812
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 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • 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.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Encrypt symbol names (snvalid)
« Reply #3 on: November 27, 2017, 11:03:29 AM »
How strong does it need to be?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • 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~©¶"
        )
    )
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • 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.  :)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • 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.  :) :) :)

gile

  • Gator
  • Posts: 2507
  • 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: 1451
  • 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.  :)