<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: XOR code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 14:50:40 GMT</pubDate>
    <description>DZone Snippets: XOR code</description>
    <item>
      <title>Logic gates in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5059</link>
      <description>&lt;code&gt;&lt;br /&gt;NAND = lambda { |i, j| !(i &amp;&amp; j) }&lt;br /&gt;NOT = lambda { |i| NAND[i, i] }&lt;br /&gt;AND = lambda { |i, j| NOT[NAND[i, j]] }&lt;br /&gt;OR = lambda { |i, j| NAND[NAND[i, i], NAND[j, j]] }&lt;br /&gt;NOR = lambda { |i, j| NOT[OR[i, j]] }&lt;br /&gt;XOR = lambda { |i, j| NAND[NAND[i, NAND[i, j]], NAND[j, NAND[i, j]]] }&lt;br /&gt;XNOR = lambda { |i, j| NOT[XOR[i, j]] }&lt;br /&gt;&lt;br /&gt;XOR[true, true] =&gt; false&lt;br /&gt;XOR[true, false] =&gt; true&lt;br /&gt;XOR[false, true] =&gt; true&lt;br /&gt;XOR[false, false] =&gt; false&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Jan 2008 03:28:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5059</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>rpatch XOR diff/patch script</title>
      <link>http://snippets.dzone.com/posts/show/1149</link>
      <description>&lt;code&gt;&lt;br /&gt;REBOL []&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;do-by-type: func [&lt;br /&gt;    value&lt;br /&gt;    actions [block!]&lt;br /&gt;    /default&lt;br /&gt;        def-action [block!]&lt;br /&gt;    /local action&lt;br /&gt;][&lt;br /&gt;    either action: select actions type?/word value [&lt;br /&gt;        ;print mold action&lt;br /&gt;        do bind/copy action 'value&lt;br /&gt;    ][&lt;br /&gt;        if default [do bind/copy def-action 'value]&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;to-binary-ex: func [value] [&lt;br /&gt;    do-by-type value [&lt;br /&gt;        binary! [value]&lt;br /&gt;        string! [to-binary value]&lt;br /&gt;        file!   [read/binary value]&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;xor-diff: func [&lt;br /&gt;    a [binary! string! file!]&lt;br /&gt;    b [binary! string! file!]&lt;br /&gt;    /local bin-a bin-b&lt;br /&gt;][&lt;br /&gt;    bin-a: to-binary-ex a&lt;br /&gt;    bin-b: to-binary-ex b&lt;br /&gt;    bin-a xor bin-b&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;make-patch: func [&lt;br /&gt;    a [binary! string! file!]&lt;br /&gt;    b [binary! string! file!]&lt;br /&gt;][&lt;br /&gt;    compress xor-diff a b&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;apply-patch: func [&lt;br /&gt;    data  [binary! string! file!]&lt;br /&gt;    patch [binary! string!]&lt;br /&gt;    /local result&lt;br /&gt;][&lt;br /&gt;    result: xor-diff data decompress patch&lt;br /&gt;    ; If they gave us a string as the source, return a string.&lt;br /&gt;    ;?? If they give us a file, should we write back out to it?&lt;br /&gt;    either string? data [to-string result][result]&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;a: "Now is the time for all good men to come to the aid of their country..."&lt;br /&gt;b: {Now is the time for all good men to come to the aid of their country...&lt;br /&gt;whether 'tis nolber to suffer the slings and arrows...}&lt;br /&gt;;d1: xor-diff a b&lt;br /&gt;p1: make-patch a b&lt;br /&gt;bp: apply-patch a p1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;change-dir %./test-files&lt;br /&gt;&lt;br /&gt;files: sort read %.&lt;br /&gt;print mold files&lt;br /&gt;print [files/1 files/2]&lt;br /&gt;fp-1-2: make-patch files/1 files/2&lt;br /&gt;fp-2-3: make-patch files/2 files/3&lt;br /&gt;fp-3-4: make-patch files/3 files/4&lt;br /&gt;fp-a-b: make-patch files/5 files/6&lt;br /&gt;&lt;br /&gt;pp-a-b: apply-patch files/5 fp-a-b&lt;br /&gt;&lt;br /&gt;change-dir %..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;halt&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 13 Jan 2006 04:15:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1149</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
