Skip to content

Commit

Permalink
Style
Browse files Browse the repository at this point in the history
  • Loading branch information
kocakosm committed Jun 25, 2015
1 parent 82bb7e1 commit a3986ba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[AUTHORS]

Osman KOÇAK <kocakosm@gmail.com>
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
Nash-Cipher
===========

[![Build Status](https://secure.travis-ci.org/kocakosm/nash-cipher.png?branch=master)](http://travis-ci.org/kocakosm/nash-cipher) [![Coverage Status](https://coveralls.io/repos/kocakosm/nash-cipher/badge.png)](https://coveralls.io/r/kocakosm/nash-cipher) [![Dependency Status](https://www.versioneye.com/user/projects/532df6a6f5994914490001c8/badge.png)](https://www.versioneye.com/user/projects/532df6a6f5994914490001c8)
Nash-Cipher [![Build][1]][2] [![Coverage][3]][4]
================================================


Overview
--------

Nash-Cipher is a simple implementation of the cipher described by
[John Nash](http://en.wikipedia.org/wiki/John_Forbes_Nash,_Jr.) in his
letters to the NSA in 1955. These letters have been declassified by the NSA and
published on their website in January 2012. For more information, please read the
[press release](http://www.nsa.gov/public_info/press_room/2012/nash_exhibit.shtml).
Nash-Cipher is a simple implementation of the cipher described by [John Nash][5]
in his letters to the NSA in 1955.

These letters have been declassified by the NSA and published on their website
in January 2012. For more information, please read the [press release][6].


License
Expand All @@ -21,12 +19,26 @@ This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

This program is distributed in the hope that it will be useful, but _without any
warranty;_ without even the implied warranty of _merchantability_ or _fitness
for a particular purpose_.

See the [GNU Lesser General Public License][7] for more details.


Contact
-------

For any question, feel free to contact me at kocakosm[@]gmail.com
If you have any question, feel free to send me an e-mail at kocakosm[@]gmail[dot]com
or ping me on [twitter][8].


[1]: https://img.shields.io/travis/kocakosm/nash-cipher.svg
[2]: https://travis-ci.org/kocakosm/nash-cipher
[3]: https://img.shields.io/coveralls/kocakosm/nash-cipher.svg
[4]: https://coveralls.io/r/kocakosm/nash-cipher
[5]: http://en.wikipedia.org/wiki/John_Forbes_Nash,_Jr.
[6]: http://www.nsa.gov/public_info/press_room/2012/nash_exhibit.shtml
[7]: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
[8]: https://twitter.com/kocakosm
40 changes: 8 additions & 32 deletions src/org/kocakosm/nash/NashCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum Mode
* @param mode the cipher's operation mode.
*
* @throws NullPointerException if one of the arguments is {@code null}.
* @throws IllegalArgumentException if {@code key} and {@code iv} have
* @throws IllegalArgumentException if {@code key} and {@code iv} have
* different sizes.
*/
public NashCipher(Key key, IV iv, Mode mode)
Expand All @@ -60,11 +60,11 @@ public NashCipher(Key key, IV iv, Mode mode)

/**
* Resets this cipher.
*
*
* @param iv the initialization vector.
*
*
* @throws NullPointerException if {@code iv} is {@code null}.
* @throws IllegalArgumentException if {@code iv}'s size doesn't match
* @throws IllegalArgumentException if {@code iv}'s size doesn't match
* the size of the cipher's key.
*/
public void reset(IV iv)
Expand Down Expand Up @@ -108,42 +108,18 @@ public byte[] process(byte[] bytes, int off, int len)
if (off < 0 || len < 0) {
throw new IndexOutOfBoundsException();
}
if (mode == Mode.ENCRYPTION) {
return encrypt(bytes, off, len);
}
return decrypt(bytes, off, len);
}

private byte[] encrypt(byte[] bytes, int off, int len)
{
byte[] encrypted = new byte[len];
for (int i = off; i < off + len; i++) {
int val = 0;
for (int j = 0; j < 8; j++) {
boolean in = ((bytes[i] & 0xFF) & (1 << j)) > 0;
boolean out = in ^ state[state.length - 1];
val = (val >>> 1) | (out ? 0x80 : 0);
process(out);
}
encrypted[i] = (byte) val;
}
return encrypted;
}

private byte[] decrypt(byte[] bytes, int off, int len)
{
byte[] decrypted = new byte[len];
byte[] processed = new byte[len];
for (int i = off; i < off + len; i++) {
int val = 0;
for (int j = 0; j < 8; j++) {
boolean in = ((bytes[i] & 0xFF) & (1 << j)) > 0;
boolean out = in ^ state[state.length - 1];
val = (val >>> 1) | (out ? 0x80 : 0);
process(in);
process(mode == Mode.DECRYPTION ? in : out);
}
decrypted[i] = (byte) val;
processed[i] = (byte) val;
}
return decrypted;
return processed;
}

private void process(boolean bit)
Expand Down

0 comments on commit a3986ba

Please sign in to comment.