• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Need XOR solution
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need XOR solution


  • Subject: Re: Need XOR solution
  • From: "Arthur J. Knapp" <email@hidden>
  • Date: Tue, 06 Aug 2002 16:33:17 -0400

> Date: Mon, 05 Aug 2002 18:45:28 -0400
> From: "Marc K. Myers" <email@hidden>
> Subject: Need XOR solution

> Does anyone know of a reasonably fast way to XOR blocks of data together?

No, but I know of "a" way to perform vanilla XORing, unfortunately a
"reasonably fast" way to do it alludes me.


> I'm working on an AppleScript implementation of a one-time pad
> crytography system. Right now I'm XORing the plaintext against the key
> using the "Bits & Bytes" osax, which requires me to convert each byte
> from each file to its ASCII number equivalent, run the "bitwiseXOR"
> command on it, and then convert the result to its ASCII character
> equivalent.

That's three osax calls per character in your plaintext. Perhaps you
might want to consider a Venigere cypher, (much easier to code).

> ... This kind of logical data manipulation is so basic that
> there's *got* to be a better approach than that!

The AppleScript design team is unlikely to have considered the
possiblity that AppleScripters would want bitwise operators, (it
is rather against the philosophy of AS). ;-)

> ... I would appreciate it
> if someone could point me in the right direction.

This is unlikely to be the right direction, but you may find
my "manual" XORing to be interesting:

-- Replace the ` character with line-continuation characters,
-- (option-L on US keyboards).

CharXOR("A", "z") --> ";"
CharXOR("2", "B") --> "p"
CharXOR("@", "!") --> "a"


property ks256 : run script "
set a to {}
repeat with i from 0 to 255
set a's end to ascii character i
end
return a as string"

on AsciiNumber(c)
set o to text item delimiters
set text item delimiters to c
set n to my ks256's text item 1's length
set text item delimiters to o
return n
end AsciiNumber

on AsciiNumber_t(c)
set text item delimiters to c
return my ks256's text item 1's length
end AsciiNumber_t

on AsciiCharacter(n)
return my ks256's item (n + 1)
end AsciiCharacter

on Bitify(n)
return {n div 128 mod 2 `
, n div 64 mod 2 `
, n div 32 mod 2 `
, n div 16 mod 2 `
, n div 8 mod 2 `
, n div 4 mod 2 `
, n div 2 mod 2 `
, n mod 2}
end Bitify

on Numify(a)
tell (a) to return `
(item 1) * 128 + `
(item 2) * 64 + `
(item 3) * 32 + `
(item 4) * 16 + `
(item 5) * 8 + `
(item 6) * 4 + `
(item 7) * 2 + `
(item 8)
end Numify

on Xorify(a, b)
set c to {}
repeat with i from 1 to 8
(*
* exclusive or:
* 0 xor 0 == 0
* 0 xor 1 == 1
* 1 xor 0 == 1
* 1 xor 1 == 0
*)
if (a's item i = b's item i) then -- not xor

set c's end to 0 -- false
else
set c's end to 1 -- true
end if
end repeat
return c
end Xorify

on CharXOR(a, b)
set o to text item delimiters
set aa to my Bitify(my AsciiNumber_t(a))
set bb to my Bitify(my AsciiNumber_t(b))
set text item delimiters to o
set cc to my Xorify(aa, bb)
return my AsciiCharacter(my Numify(cc))
end CharXOR


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: is this a bug?
  • Next by Date: Re: Labels of a Record
  • Previous by thread: Re: Need XOR solution
  • Next by thread: Re: Need XOR solution
  • Index(es):
    • Date
    • Thread