# The ISAAC cipher

```ruby
require('Math::Random::ISAAC')
 
func xor_isaac(key, msg) {
  var rng = %O<Math::Random::ISAAC>.new(unpack('C*', key))
 
  msg.chars»ord()»                                          \
    -> »^« 256.of{ rng.irand % 95 + 32 }.last(msg.len).flip \
    -> «%« '%02X' -> join
}
 
var msg = 'a Top Secret secret'
var key = 'this is my secret key'
 
var enc = xor_isaac(key, msg)
var dec = xor_isaac(key, pack('H*', enc))
 
say "Message: #{msg}"
say "Key    : #{key}"
say "XOR    : #{enc}"
say "XOR dcr: #{pack('H*', dec)}"
```

#### Output:

```
Message: a Top Secret secret
Key    : this is my secret key
XOR    : 1C0636190B1260233B35125F1E1D0E2F4C5422
XOR dcr: a Top Secret secret
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/t/the_isaac_cipher.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
