# arc4

> rc4 stream cipher

Latest version **3.4.0** (published 2017-12-31) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install arc4
pnpm add arc4
yarn add arc4
bun add arc4
```

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.4.0 |
| Published | 2017-12-31 |
| First published | 2014-06-23 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | separate (@types/arc4) |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+10 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | hex7c0 |
| Maintainers | hex7c0 |
| Keywords | rc4, stream, cipher |

## Links

- npm: https://www.npmjs.com/package/arc4
- Repository: https://github.com/hex7c0/arc4
- Issues: https://github.com/hex7c0/arc4/issues
- npm.io page: https://npm.io/package/arc4

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) 4.17.4

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 3.4.0 (latest) — 2017-12-31
- 3.3.8 — 2017-05-28
- 3.3.7 — 2016-11-13
- 3.3.6 — 2016-09-20
- 3.3.5 — 2016-09-12
- 3.3.4 — 2016-05-21
- 3.3.3 — 2016-05-03
- 3.3.2 — 2016-04-12
- 3.3.1 — 2016-03-29
- 3.3.0 — 2016-01-13
- 3.2.1 — 2015-10-31
- 3.2.0 — 2015-08-29
- 3.1.3 — 2015-07-14
- 3.1.2 — 2015-06-09
- 3.1.1 — 2015-04-18
- … 25 more at https://npm.io/package/arc4/versions

## README

# [arc4](https://github.com/hex7c0/arc4)

[![NPM version](https://img.shields.io/npm/v/arc4.svg)](https://www.npmjs.com/package/arc4)
[![Linux Status](https://img.shields.io/travis/hex7c0/arc4.svg?label=linux-osx)](https://travis-ci.org/hex7c0/arc4)
[![Windows Status](https://img.shields.io/appveyor/ci/hex7c0/arc4.svg?label=windows)](https://ci.appveyor.com/project/hex7c0/arc4)
[![Dependency Status](https://img.shields.io/david/hex7c0/arc4.svg)](https://david-dm.org/hex7c0/arc4)
[![Coveralls](https://img.shields.io/coveralls/hex7c0/arc4.svg)](https://coveralls.io/r/hex7c0/arc4)

[RC4](https://en.wikipedia.org/wiki/RC4) stream cipher.
You can select from ["[arc4](https://en.wikipedia.org/wiki/RC4)", "[rc4a](https://en.wikipedia.org/wiki/RC4#RC4A)", "[vmpc](https://en.wikipedia.org/wiki/RC4#VMPC)", "[rc4+](https://en.wikipedia.org/wiki/RC4#RC4.2B)"] algorithm

Encode/decode with different [encodings](http://nodejs.org/api/buffer.html#apicontent) _for *String only_, from nodejs doc:
> - 'ascii' - for 7 bit ASCII data only. This encoding method is very fast, and will strip the high bit if set.
> - 'utf8' - Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
> - 'utf16le' - 2 or 4 bytes, little endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
> - 'ucs2' - Alias of 'utf16le'.
> - 'base64' - Base64 string encoding.
> - 'binary' - A way of encoding raw binary data into strings by using only the first 8 bits of each character. This encoding method is deprecated and should be avoided in favor of Buffer objects where possible. This encoding will be removed in future versions of Node.
> - 'hex' - Encode each byte as two hexadecimal characters.

My original [python code](https://github.com/hex7c0/EncryptoPy/blob/master/modules/rc/rc4.py)

## Installation

Install through NPM

```bash
npm install arc4
```
or
```bash
git clone git://github.com/hex7c0/arc4.git
```

## API

inside nodejs project
```js
var rc4 = require('arc4');

var cipher = rc4('arc4', 'secret_key');
var d = cipher.encodeString('ciao');
var e = cipher.decodeString(d);
```

### Methods

change your key and reload [gKsa](https://en.wikipedia.org/wiki/RC4#Key-scheduling_algorithm_.28KSA.29) (warning)
```js
cipher.change('foo');
cipher.change([30, 31]);
cipher.change(new Buffer('foo'));
```

encode a plaintext string, you can optionally choose input (defaults to 'utf8') and output (defaults to 'hex') [encoding](http://nodejs.org/api/buffer.html#apicontent)
```js
cipher.encodeString(plaintext [, input_encoding [, output_encoding]]);
cipher.encodeString('string', 'utf8', 'base64');
```

encode a plaintext array
```js
cipher.encodeArray([49, 50, 51]);
```

encode a plaintext buffer data
```js
cipher.encodeBuffer(new Buffer('ciao'));
```

select right function according with plaintext data type. Set input and output [encoding](http://nodejs.org/api/buffer.html#apicontent) only if data is a String
```js
cipher.encode(your_data [, input_encoding [, output_encoding]]);
```

decode a ciphertext string, you can optionally choose input (defaults to 'hex') and output (defaults to 'utf8') [encoding](http://nodejs.org/api/buffer.html#apicontent)
```js
cipher.decodeString(ciphertext [, input_encoding [, output_encoding]]);
cipher.decodeString('string', 'utf8', 'base64');
```

decode a ciphertext array
```js
cipher.decodeArray([49,50,51]);
```

decode a ciphertext buffer data
```js
cipher.decodeBuffer(new Buffer('ciao'));
```

select right function according with ciphertext data type. Set input and output [encoding](http://nodejs.org/api/buffer.html#apicontent) only if data is a String
```js
cipher.decode(your_data [, input_encoding [, output_encoding]]);
```

### rc4(algorithm, password [, lodash])

#### algorithm

 - `algorithm` - **String** Choose between ["[arc4](https://en.wikipedia.org/wiki/RC4)", "[rc4a](https://en.wikipedia.org/wiki/RC4#RC4A)", "[vmpc](https://en.wikipedia.org/wiki/RC4#VMPC)", "[rc4+](https://en.wikipedia.org/wiki/RC4#RC4.2B)"] *(default "throw Error")*

#### password

 - `password` - **String | Array | Buffer** Your key *(default "throw Error")*

#### [lodash]

 - `lodash` - **Boolean** Use [lodash](http://lodash.com/) library (check [benchmark](test/benchmark.js) test for right decision) *(default "disabled")*

## Examples

Take a look at my [examples](examples)

### [License GPLv3](license)

---
_Source: https://npm.io/package/arc4 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
