Giter Club home page Giter Club logo

sdes's Introduction

BufferCrypt

BufferCrypt contains a Simple DES implementation with javascript. S-DES is a didatic implementation of DES algorithm.

Using

First, import the dist/index.js file. It contain a BufferCrypt object with sdesEncrypt and sdesDecrypt static functions

  const BufferCrypt = require('./dist/index.js');
BufferCrypt.sdesEncrypt(key, buffer)
BufferCrypt.sdesDecrypt(key, buffer)

key is a integer key with 10 bits, that means betwen 0 and 1023. buffer is a node Buffer, see https://nodejs.org/api/buffer.html to more explanation.

Development

To use in development, you should install the dependencies and run npm as dev mode. It will watch your files and automatically reload the application per update.

npm install
npm run dev

Example

  var BufferCrypt = require('./dist/index.js');
  
  let raw = new Buffer('|><+-àèìÒù');
  
  let key = 666;
  let enc = BufferCrypt.sdesEncrypt(key, raw);
  let dec = BufferCrypt.sdesDecrypt(key, enc);                                                                                         
  
  console.log(`using key ${key}`);                                                                                                     
  
  console.log(`original  = ${raw.toString()}`);
  console.log(`encrypted = ${enc.toString()}`);
  console.log(`decrypted = ${dec.toString()}`);
  
  console.log('Buffers');
                                                                                          
  console.log("original");
  console.log(raw);
  console.log("encrypted");
  console.log(enc);
  console.log("decrypted");
  console.log(dec)

It will produces

using key 666
original  = |><+-àèìÒù
encrypted = Ln�}�������
                       �5
decrypted = |><+-àèìÒù

Buffers

original
<Buffer 7c 3e 3c 2b 2d c3 a0 c3 a8 c3 ac c3 92 c3 b9>
encrypted
<Buffer 4c 6e dc 7d 13 e9 d9 e9 a0 e9 e5 e9 0b e9 35>
decrypted
<Buffer 7c 3e 3c 2b 2d c3 a0 c3 a8 c3 ac c3 92 c3 b9>

TODO

  • Great refactor
  • Specs

Some references

http://homepages.gac.edu/~holte/courses/mcs150-J01/documents/DESinstructions.html

http://homepages.gac.edu/~holte/courses/mcs150-J01/documents/DESexample.html

sdes's People

Contributors

ottony avatar

Stargazers

birb avatar Kauê Buriti avatar Bruno Costa - Garu avatar Ewerton avatar

Watchers

 avatar

sdes's Issues

Not always correct

This doesn't seem to always be correct. When encrypting 7 with the key 1111110110, you'd expect an output of 158, but instead you get 154. Another example is encrypting 217, you'd expect 98 but you get 39.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.