NYC 2600

Started by newdep, January 15, 2007, 02:45:28 PM

Previous topic - Next topic

newdep

Network Programming and Distributed Scripting with newLISP



http://nyc2600.net/2007/01/14/new-2600-issue/">http://nyc2600.net/2007/01/14/new-2600-issue/



http://store.2600.com/winter200607.html">http://store.2600.com/winter200607.html



I did not read it yet, but I saw somewhere here a link on this forum

from the guy how wrote it ;-)



Can you post your article here (or somehwere)?

The magazine is not deliverable in Europe ;-)
-- (define? (Cornflakes))

Ryon

#1
The Winter 2006-2007 issue of 2600 doesn't seem to be on Gnutella quite yet. That would be the hackerly way to get a copy.
\"Give me a Kaypro 64 and a dial tone, and I can do anything!\"

ax0n

#2
Hey guys.  That was my article.  2600 says that once an article gets printed, the author may do whatever they want with it.  This is the fourth article I've had published, and as usual, I've posted it publicly.  The whole article as well as friendly downloadable code samples are available at the link below.  Thanks for taking notice.  I hope you enjoy the article.



http://www.focushacks.com/?block=2600-nl">http://www.focushacks.com/?block=2600-nl



Please keep in mind that I still have very little actual newLISP experience.  I took a month off when I left the little start-up I'd been working for, and spent quite a bit of time tinkering.  newLISP was certainly one of the many things that occupied my time.

cormullion

#3
Good job! Great article - I look forward to reading some more some time... So write some more!



(and thanks for the mention :-)

ax0n

#4
My old crew (HiR e-Zine from back in the late 90's) has set up a blog.



http://h-i-r.blogspot.com/">http://h-i-r.blogspot.com/



We've been discussing (in an email thread and at the recent 2600 meetings) cryptography, specifically the XOR variety that's simple yet powerful.  I decided to write a quick little newLISP tutorial.  I am aware of newLISP's "encrypt" function which I haven't tested.



This was more to create a visible demonstration of how XOR encryption works.  newLISP does the job very well!  Then, I continue to build on that by explaining that XOR encryption in and of itself isn't unbreakable, but with proper protocol, it's very powerful.

newdep

#5
I like the articles on newlisp ;-)  keep it coming..
-- (define? (Cornflakes))

ax0n

#6
I actually have an update to that article that I plan on posting tomorrow.  The article is done, but I'm pacing myself.  This can take a very random piece of key data (such as a file made from /dev/urandom output) and can encrypt simple plaintext or binary content (images, executables, etc) without a problem.  



#!/usr/bin/newlisp
(set 'params (main-args))
(if (< (length params) 6)
  (begin
    (println "USAGE: crypt.lsp <pad> <file> <output> <padremainder>")
    (exit)
  )
)
(set 'pad (nth 2 params))
(set 'file (nth 3 params))
(set 'out (nth 4 params))
(set 'padr (nth 5 params))
(set 'padfh (open pad "read"))
(set 'filefh (open file "read"))
(set 'outfh (open out "write"))
(set 'padrfh (open padr "write"))
(while (set 'filechr (read-char filefh))
  (set 'padchr (read-char padfh))
  (set 'xor (^ filechr padchr))
  (write-char outfh xor)
)

while (set 'padchr (read-char padfh))
  (write-char padrfh padchr)
)
(close padfh)
(close padrfh)
(close filefh)
(close outfh)
(exit)

Lutz

#7
Yoy could make this program much shorter and faster using newLISP's built-in 'encrypt' function, which also does one-pad XOR encryption. See here:



http://newlisp.org/downloads/newlisp_manual.html#encrypt">http://newlisp.org/downloads/newlisp_ma ... ml#encrypt">http://newlisp.org/downloads/newlisp_manual.html#encrypt



Lutz

Lutz

#8
... this is the commandline utility I am using:


#!/usr/bin/newlisp

(set 'fname (main-args 2))
(print "Passphrase:")
(write-file (append fname ".enc") (encrypt (read-file fname) (read-line)))
(exit)


Because it is XOR based it works both ways for enryption and decryption.



Lutz

ax0n

#9
Quote from: "Lutz"... this is the commandline utility I am using:


#!/usr/bin/newlisp

(set 'fname (main-args 2))
(print "Passphrase:")
(write-file (append fname ".enc") (encrypt (read-file fname) (read-line)))
(exit)


Because it is XOR based it works both ways for enryption and decryption.



Lutz


I wasn't sure how encrypt works.  So, it does the same thing my program does, but loops the key if it is shorter than the clear?



I will try this:

#!/usr/bin/newlisp

(set 'pad (main-args 2))

(set 'target (main-args 3))

(write-file (append target ".enc") (encrypt (read-file target) (read-file pad)))

(exit)



resulting cipher is the same.  crypt.txt was made with my tool from a few posts ago.  clear.txt.enc was made with the above code derived from Lutz's example.



~/test $ hexdump crypt.txt              

0000000 84fd 7697 3858 6738 1641 ee11 9008 c366

0000010 5fdd 1b5e a3b5 b2f9 1079 144f 40ce 0029

000001f



~/test $ hexdump clear.txt.enc

0000000 84fd 7697 3858 6738 1641 ee11 9008 c366

0000010 5fdd 1b5e a3b5 b2f9 1079 144f 40ce 0029

000001f



I love newlisp.  :)



 I will update my code and my article before I post it.  Thanks for your help.  I'm still a newbie, but learning!

ax0n

#10
Here's the code I'll be using for my next article.  It works the same but is more compact, with all of the core logic on one line, and a second line to write the pad remainder file out.



#!/usr/bin/newlisp
(set 'params (main-args))
(if (< (length params) 5)
  (begin
    (println "USAGE: crypt.lsp [pad] [file] [output] [pad-remainder]")
    (exit)
  )
)
(set 'pad (params 2))
(set 'target (params 3))
(set 'output (params 4))
(set 'remainder (params 5))
(write-file output (encrypt (read-file target) (read-file pad)))
(write-file remainder (slice (read-file pad) (length (read-file target))))
(exit)

Lutz

#11
QuoteI wasn't sure how encrypt works. So, it does the same thing my program does, but loops the key if it is shorter than the clear?


Yes, exactly. In your program that means, that there will only be a remainder when the pad is longer than the target, else 'encrypt' will apply the pad over and over. Allthough for the last piece in the file only part of the pad may be applied, if the clear-length is not an integer multiple of the pad-length.



Lutz

cormullion

#12
nice blog, ax0n. Keep it up! In my experience, starting a blog is easier than keeping it going... :-)



By the way - if you find the single-statement 'if' a bit strange, you could think about using 'cond'. Replace the 'if' with 'cond' and enclose each set of test/action(s) in parentheses. Eg:


(cond
  ((< (length params) 5)
     (println "USAGE: crypt.lsp [pad] [file] [output] [pad-remainder]")
     (exit))
...
)


which avoids the 'begin'. Also, you can set your symbols in a single statement:


set 'pad (params 2) 'target (params 3) 'output (params 4)  'remainder (params 5))

which kind of suggests this:


(map set '(pad target output remainder) (rest (rest (main-args))))

which is cool and Lispy. Then you could refactor as follows:


(cond
  ((< (length (main-args)) 5)
     (println "USAGE: crypt.lsp [pad] [file] [output] [pad-remainder]"))
  (true
     (map set '(pad target output remainder) (rest (rest (main-args))))
     (write-file output (encrypt (read-file target) (read-file pad)))
     (write-file remainder (slice (read-file pad) (length (read-file target))))))

(exit)


The thing I like a lot about newLISP is how it encourages you to find a way of expressing something that feels just right: and we all have our own style, which is good.



Keep up the newLISP posts! :-)

ax0n

#13
Quote from: "cormullion"nice blog, ax0n. Keep it up! In my experience, starting a blog is easier than keeping it going... :-)


I've been keeping this one up with an average of two posts per day on weekdays.



http://kc-bike.blogspot.com/">http://kc-bike.blogspot.com/



And prior to this blog, my friends and I that are writing on this blog kept a bi-monthly e-zine up (mad textfiles, yo!) for a few years.  I'm very, very random though, so I can't promise tons of newlisp articles.  I have fallen in love with the language though.  I just have to find time to play with it and ideas for implementing it.



There will still be another newlisp article soon.  I will probably post it this evening or tomorrow.