Giter Site home page Giter Site logo

mycipher's Introduction

My Cipher

Designed by Yoshiura

Environment

ruby 2.3.3

Algorithm

Usage

cipher =  MyCipher.new(bit_length, secret_key, secret_key) # 鍵が2つあるのはいつか公開鍵になるかもしれないので一応

# 平文
a = 10
b = 5

# 暗号化 暗号文は配列 bit_length = 8[bit]
c1 = cipher.encrypt(a)
=> [308, 1554, 1645, 4417, 5398, 4291, 1345, 1897] 
c2 = cipher.encrypt(b)
=> [973, 420, 3094, 5824, 6384, 2171, 3402, 4327]

# 暗号文での計算たち

# 等号判定
c3 = cipher.c_equal?(c1, c2)
[36849990111486836334907197600000, 271868233933242509485656333600000, 17102270716882031449614029184000, 9704099300730617939494964472000, 10368572104414170797539494705600, 13235491425642149454763410966528, 29897375235521161633452686822400, 159968231351362235045404899187020000]
cipher.decrypt(c3)
=> 0 # (復号して1だったら等しい)

# 暗号文のbit反転(びみょう)
c4 = cipher.c_not(c1)
=> [4096, 5342, 5433, 8205, 9186, 8079, 5133, 5685]
cipher.decrypt(c4)
=> 245

# 暗号文のand計算
c5 = cipher.c_and(c1, c2)
=> [299684, 652680, 5089630, 25724608, 34460832, 9315761, 4575690, 8208319]
cipher.decrypt(c5)
=> 0

# 暗号文のxor計算
c6 = cipher.c_xor(c1, c2)
=> [1281, 1974, 4739, 10241, 11782, 6462, 4747, 6224]
cipher.decrypt(c6)
=> 15


cipher.decrypt(c1)
=> 10
cipher.decrypt(c2)
=> 5

mycipher's People

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.