Giter Site home page Giter Site logo

runetopic / cryptography Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 301 KB

Useful cryptography algorithm implementations used throughout the Runetopic organization.

License: MIT License

Kotlin 100.00%
xtea-cipher whirlpool xtea isaac hashing encryption decryption cryptography huffman huffman-coding

cryptography's Introduction

Cryptography

Useful cryptography algorithms used throughout the RuneTopic organization.

Gradle

cryptography = { module = "com.runetopic.cryptography:cryptography", version.ref "1.2.0-SNAPSHOT" }

XTEA

Decryption

val bytes = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7)
val decrypted = bytes.fromXTEA(rounds = 32, keys = IntArray(4))

val expected = "[-22, 56, -103, 36, 1, 86, -95, 47]"
assertEquals(expected, decrypted.contentToString())

Encryption

val bytes = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7)
val encrypted = bytes.toXTEA(rounds = 32, keys = IntArray(4))

val expected = "[66, 17, 12, 6, 43, 119, -47, 120]"
assertEquals(expected, encrypted.contentToString())

Whirlpool

Hashing

val input = "The quick brown fox jumps over the lazy dog"
val hash = input.toByteArray().toWhirlpool(rounds = 10, size = 64)

val expected = "B97DE512E91E3828B40D2B0FDCE9CEB3C4A71F9BEA8D88E75C4FA854DF36725FD2B52EB6544EDCACD6F8BEDDFEA403CB55AE31F03AD62A5EF54E42EE82C3FB35"
assertEquals(expected, hash.joinToString("") { "%02X".format(it) })

ISAAC

val seed = IntArray(4)
val isaac = seed.toISAAC()
val random = isaac.getNext()

val expected = 405143795
assertEquals(expected, random)

Huffman

Input

val input = "A_DEAD_DAD_CEDED_A_BAD_BABE_A_BEADED_ABACA_BED"
// The sizes below can be loaded from: index(indexId = 10).group(groupName = "huffman").file(0).data
val sizes = byteArrayOf(22, 22, 22, 22, 22, 22, 21, 22, 22, 20, 22, 22, 22, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 3, 8, 22, 16, 22, 16, 17, 7, 13, 13, 13, 16, 7, 10, 6, 16, 10, 11, 12, 12, 12, 12, 13, 13, 14, 14, 11, 14, 19, 15, 17, 8, 11, 9, 10, 10, 10, 10, 11, 10, 9, 7, 12, 11, 10, 10, 9, 10, 10, 12, 10, 9, 8, 12, 12, 9, 14, 8, 12, 17, 16, 17, 22, 13, 21, 4, 7, 6, 5, 3, 6, 6, 5, 4, 10, 7, 5, 6, 4, 4, 6, 10, 5, 4, 4, 5, 7, 6, 10, 6, 10, 22, 19, 22, 14, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 21, 22, 21, 22, 22, 22, 21, 22, 22)

Compression

val huffman = Huffman(sizes = sizes)
val compressed = ByteArray(256)
val offset = input.compressHuffman(huffman, compressed)
assertEquals(60, offset)

Decompression

val decompressedString = compressed.decompressHuffman(huffman, input.length)
assertEquals(input, decompressedString)

cryptography's People

Contributors

tyler27 avatar ultraviolet-jordan avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.