Lisp lệnh ENC DEC trong chủ đề “chuyển chữ thành số”
Lisp lỗi rồi bạn ơi không chạy được. Còn nếu bạn muốn mã hoá text thì code đây (cái này không nhớ của bác nào viết hình như của bác Tue_VN hày Gia_bach ý);; free lisp from cadviet.com ;Chuong ma hoa chuoi theo thuat toan Ceasar (DEFUN ENCRYPT(str n / i l str1 m) (setq str1 "a") (setq l (strlen str)) (setq i 1) (while (<= i l) (setq c (substr str i 1)) (setq m (- (ascii c) 32)) (setq m (+ m n)) (while (< m 0) (setq m (+ m 224)) ) (setq m (MOD m 224)) (setq str1 (strcat str1 (chr (nth m LiAlpha)))) (setq i (1+ i)) ) (setq str1 (substr str1 2)) str1 ) (DEFUN DECRYPT (str n / i l str1 m) (setq str1 "a") (setq l (strlen str)) (setq i 1) (while (<= i l) (setq c (substr str i 1)) (setq m (- (ascii c) 32)) (setq m (- m n)) (while (< m 0) (setq m (+ m 224)) ) (setq m (MOD m 224)) (setq str1 (strcat str1 (chr (nth m LiAlpha)))) (setq i (1+ i)) ) (setq str1 (substr str1 2)) str1 ) (DEFUN SETALPHA( / Li) (setq Li (List)) (setq i 32) (while (<= i 255) (setq Li (append Li (List i))) (setq i (1+ i)) ) (setq LiAlpha Li) ) (DEFUN MOD (m n / kq) (while (>= m n) (setq m (- m n)) ) (setq kq m) kq ) (DEFUN C:ENC (/ ss str str0) (SETALPHA) (setvar "CMDECHO" 0) (princ "\nChon doi tuong can ma hoa:") (setq ss (ssget '((-4 . "")))) (setq m (getint "Cho biet ma khoa: ")) (setq i 0) (setq dt (ssname ss 0)) (setq n (sslength ss)) (setq i 0) (while (< i n) (setq dt (ssname ss i)) (setq str (GETCONTENT dt)) (setq str0 str) (if (= (TENDOITUONG dt) "TEXT") (setq str (ENCRYPT str m)) (setq str (ENC_MTEXT str m)) ) (setq obj (entget dt)) (setq obj (subst (cons 1 str) (cons 1 str0) obj)) (entmod obj) (entupd dt) (setq i (1+ i)) ) (setvar "CMDECHO" 0) (princ) ) (DEFUN C:DEC (/ ss str str0) (SETALPHA) (setvar "CMDECHO" 0) (princ "\nChon doi tuong can giai ma:") (setq ss (ssget '((-4 . "")))) (setq m (getint "Cho biet ma khoa: ")) (setq i 0) (setq dt (ssname ss 0)) (setq n (sslength ss)) (setq i 0) (while (< i n) (setq dt (ssname ss i)) (setq str (GETCONTENT dt)) (setq str0 str) (if (= (TENDOITUONG dt) "TEXT") (setq str (DECRYPT str m)) (setq str (DEC_MTEXT str m)) ) (setq obj (entget dt)) (setq obj (subst (cons 1 str) (cons 1 str0) obj)) (entmod obj) (entupd dt) (setq i (1+ i)) ) (setvar "CMDECHO" 0) (princ) ) (DEFUN ENC_MTEXT(str m / LiStr i encstr n) (setq LiStr (List)) (setq encstr "a") (setq i (POSTSTR str "\\P")) (if (= i 0) (setq LiStr (Append LiStr (List str))) (progn (while (> i 0) (setq temp (substr str 1 (1- i))) (setq LiStr (Append LiStr (List temp))) (setq str (substr str (+ i 2))) (setq i (POSTSTR str "\\P")) ) (setq LiStr (Append LiStr (List str))) ) ) (setq n (length LiStr)) (setq i 0) (while(< i n) (setq encstr (strcat encstr "\\P" (ENCRYPT (nth i LiStr) m))) (setq i (+ i 1)) ) (setq encstr (substr encstr 4)) encstr ) (DEFUN DEC_MTEXT(str m / LiStr i decstr n) (setq LiStr (List)) (setq decstr "a") (setq i (POSTSTR str "\\P")) (if (= i 0) (setq LiStr (Append LiStr (List str))) (progn (while (> i 0) (setq temp (substr str 1 (1- i))) (setq LiStr (Append LiStr (List temp))) (setq str (substr str (+ i 2))) (setq i (POSTSTR str "\\P")) ) (setq LiStr (Append LiStr (List str))) ) ) (setq n (length LiStr)) (setq i 0) (while(< i n) (setq decstr (strcat decstr "\\P" (DECRYPT (nth i LiStr) m))) (setq i (+ i 1)) ) (setq decstr (substr decstr 4)) decstr ) (DEFUN GETCONTENT (obj / cont) (setq cont (cdr (assoc 1 (entget obj)))) cont ) (DEFUN POSTSTR(str0 str / vt i l0 l) (setq vt 0) (setq l0 (strlen str0)) (setq l (strlen str)) (setq i 1) (while (< i (- l0 l -1)) (if (= (substr str0 i l) str) (progn (setq vt i) (setq i l0) ) ) (setq i (1+ i)) ) vt ) (DEFUN TENDOITUONG (obj / name) (setq name (CDR (ASSOC 0 (ENTGET obj)))) name )
Không lỗi đâu bảng mã ASCII là bảng chữ cái không dấu bác à. Đánh không dấu nhé!
- Tải lisp
- 111448_enc_dec.lsp
Cách dùng
- Tải tệp 111448_enc_dec.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh ENC DEC để chạy lisp.
Mã nguồn 111448_enc_dec.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/25871-chuy%E1%BB%83n-ch%E1%BB%AF-th%C3%A0nh-s%E1%BB%91/
;; free lisp from cadviet.com
;Chuong ma hoa chuoi theo thuat toan Ceasar
(DEFUN ENCRYPT(str n / i l str1 m)
(setq str1 "a")
(setq l (strlen str))
(setq i 1)
(while (<= i l)
(setq c (substr str i 1))
(setq m (- (ascii c) 32))
(setq m (+ m n))
(while (< m 0)
(setq m (+ m 224))
)
(setq m (MOD m 224))
(setq str1 (strcat str1 (chr (nth m LiAlpha))))
(setq i (1+ i))
)
(setq str1 (substr str1 2))
str1
)
(DEFUN DECRYPT (str n / i l str1 m)
(setq str1 "a")
(setq l (strlen str))
(setq i 1)
(while (<= i l)
(setq c (substr str i 1))
(setq m (- (ascii c) 32))
(setq m (- m n))
(while (< m 0)
(setq m (+ m 224))
)
(setq m (MOD m 224))
(setq str1 (strcat str1 (chr (nth m LiAlpha))))
(setq i (1+ i))
)
(setq str1 (substr str1 2))
str1
)
(DEFUN SETALPHA( / Li)
(setq Li (List))
(setq i 32)
(while (<= i 255)
(setq Li (append Li (List i)))
(setq i (1+ i))
)
(setq LiAlpha Li)
)
(DEFUN MOD (m n / kq)
(while (>= m n)
(setq m (- m n))
)
(setq kq m)
kq
)
(DEFUN C:ENC (/ ss str str0)
(SETALPHA)
(setvar "CMDECHO" 0)
(princ "\nChon doi tuong can ma hoa:")
(setq ss (ssget '((-4 . ""))))
(setq m (getint "Cho biet ma khoa: "))
(setq i 0)
(setq dt (ssname ss 0))
(setq n (sslength ss))
(setq i 0)
(while (< i n)
(setq dt (ssname ss i))
(setq str (GETCONTENT dt))
(setq str0 str)
(if (= (TENDOITUONG dt) "TEXT")
(setq str (ENCRYPT str m))
(setq str (ENC_MTEXT str m))
)
(setq obj (entget dt))
(setq obj (subst (cons 1 str) (cons 1 str0) obj))
(entmod obj)
(entupd dt)
(setq i (1+ i))
)
(setvar "CMDECHO" 0)
(princ)
)
(DEFUN C:DEC (/ ss str str0)
(SETALPHA)
(setvar "CMDECHO" 0)
(princ "\nChon doi tuong can giai ma:")
(setq ss (ssget '((-4 . ""))))
(setq m (getint "Cho biet ma khoa: "))
(setq i 0)
(setq dt (ssname ss 0))
(setq n (sslength ss))
(setq i 0)
(while (< i n)
(setq dt (ssname ss i))
(setq str (GETCONTENT dt))
(setq str0 str)
(if (= (TENDOITUONG dt) "TEXT")
(setq str (DECRYPT str m))
(setq str (DEC_MTEXT str m))
)
(setq obj (entget dt))
(setq obj (subst (cons 1 str) (cons 1 str0) obj))
(entmod obj)
(entupd dt)
(setq i (1+ i))
)
(setvar "CMDECHO" 0)
(princ)
)
(DEFUN ENC_MTEXT(str m / LiStr i encstr n)
(setq LiStr (List))
(setq encstr "a")
(setq i (POSTSTR str "\\P"))
(if (= i 0)
(setq LiStr (Append LiStr (List str)))
(progn
(while (> i 0)
(setq temp (substr str 1 (1- i)))
(setq LiStr (Append LiStr (List temp)))
(setq str (substr str (+ i 2)))
(setq i (POSTSTR str "\\P"))
)
(setq LiStr (Append LiStr (List str)))
)
)
(setq n (length LiStr))
(setq i 0)
(while(< i n)
(setq encstr (strcat encstr "\\P" (ENCRYPT (nth i LiStr) m)))
(setq i (+ i 1))
)
(setq encstr (substr encstr 4))
encstr
)
(DEFUN DEC_MTEXT(str m / LiStr i decstr n)
(setq LiStr (List))
(setq decstr "a")
(setq i (POSTSTR str "\\P"))
(if (= i 0)
(setq LiStr (Append LiStr (List str)))
(progn
(while (> i 0)
(setq temp (substr str 1 (1- i)))
(setq LiStr (Append LiStr (List temp)))
(setq str (substr str (+ i 2)))
(setq i (POSTSTR str "\\P"))
)
(setq LiStr (Append LiStr (List str)))
)
)
(setq n (length LiStr))
(setq i 0)
(while(< i n)
(setq decstr (strcat decstr "\\P" (DECRYPT (nth i LiStr) m)))
(setq i (+ i 1))
)
(setq decstr (substr decstr 4))
decstr
)
(DEFUN GETCONTENT (obj / cont)
(setq cont (cdr (assoc 1 (entget obj))))
cont
)
(DEFUN POSTSTR(str0 str / vt i l0 l)
(setq vt 0)
(setq l0 (strlen str0))
(setq l (strlen str))
(setq i 1)
(while (< i (- l0 l -1))
(if (= (substr str0 i l) str)
(progn
(setq vt i)
(setq i l0)
)
)
(setq i (1+ i))
)
vt
)
(DEFUN TENDOITUONG (obj / name)
(setq name (CDR (ASSOC 0 (ENTGET obj))))
name
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề chuyển chữ thành số. Xem đúng bài viết #111448 để đọc hướng dẫn và trao đổi thêm.