From a3986ba2786cfd52d22b5c80ec6ed3e8e530079f Mon Sep 17 00:00:00 2001 From: Osman KOCAK Date: Thu, 25 Jun 2015 23:29:03 +0200 Subject: [PATCH] Style --- AUTHORS | 1 + README.md | 38 ++++++++++++++++--------- src/org/kocakosm/nash/NashCipher.java | 40 ++++++--------------------- 3 files changed, 34 insertions(+), 45 deletions(-) diff --git a/AUTHORS b/AUTHORS index 91c74c0..482ece3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,2 +1,3 @@ [AUTHORS] + Osman KOÇAK diff --git a/README.md b/README.md index 0f4afd8..992d03a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/src/org/kocakosm/nash/NashCipher.java b/src/org/kocakosm/nash/NashCipher.java index b15a0ab..dbc1ca7 100644 --- a/src/org/kocakosm/nash/NashCipher.java +++ b/src/org/kocakosm/nash/NashCipher.java @@ -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) @@ -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) @@ -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)