kotlin-hashids alternatives and similar libraries
Based on the "Misc" category.
Alternatively, view kotlin-hashids alternatives based on common mentions on social networks and blogs.
-
jclasslib
jclasslib bytecode editor is a tool that visualizes all aspects of compiled Java class files and the contained bytecode. -
kotlin-logging
Lightweight Multiplatform logging framework for Kotlin. A convenient and performant logging facade. -
lingua
The most accurate natural language detection library for Java and the JVM, suitable for long and short text alike -
Kotlift
DISCONTINUED. Kotlift is the first source-to-source language transpiler from Kotlin to Swift -
Humanizer.jvm
Humanizer.jvm meets all your jvm needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities. -
klutter
A mix of random small libraries for Kotlin, the smallest reside here until big enough for their own repository. -
solr-undertow
Solr / SolrCloud running in high performance server - tiny, fast startup, simple to configure, easy deployment without an application server. -
kassava
This library provides some useful kotlin extension functions for implementing toString(), hashCode() and equals() without all of the boilerplate. -
SimpleDNN
SimpleDNN is a machine learning lightweight open-source library written in Kotlin designed to support relevant neural network architectures in natural language processing tasks -
kasechange
๐ซ๐๐ข๐ ฟ Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case -
kotlin-futures
A collections of extension functions to make the JVM Future, CompletableFuture, ListenableFuture API more functional and Kotlin like. -
PrimeCalendar
PrimeCalendar provides all of the java.util.Calendar functionalities for Persian, Hijri, and ... dates. It is also possible to convert dates to each other. -
log4k
Lightweight logging library for Kotlin/Multiplatform. Supports Android, iOS, JavaScript and plain JVM environments.
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of kotlin-hashids or a related project?
README
Hashids.kt
A Kotlin class to generate YouTube-like hashes from one or many numbers.
Ported from Java Hashids.java by fanweixiao (is port of javascript hashids.js by Ivan Akimov)
What is it?
Hashids (Hash ID's) creates short, unique, decryptable hashes from unsigned (long) integers.
This algorithm tries to satisfy the following requirements:
- Hashes must be unique and decryptable.
- They should be able to contain more than one integer (so you can use them in complex or clustered systems).
- You should be able to specify minimum hash length.
- Hashes should not contain basic English curse words (since they are meant to appear in public places - like the URL).
Instead of showing items as 1
, 2
, or 3
, you could show them as U6dc
, u87U
, and HMou
.
You don't have to store these hashes in the database, but can encrypt + decrypt on the fly.
All (long) integers need to be greater than or equal to zero.
Usage
Import the package
import org.hashids;
Encrypting one number
You must pass a unique salt string so your hashes differ from everyone. I use "this is my salt" as an example.
val hashids = Hashids("this is my salt")
val hash: String = hashids.encode(12345)
hash
is now going to be: NkK9
Decrypting
Notice: during decryption, the same salt value has to be used:
val hashids = Hashids("this is my salt")
val numbers: LongArray = hashids.decode("NkK9")
val numver: Int = numbers[0]
numbers
is now going to be: [12345]
number
is: 12345
Decrypting with different salt
Decryption will not work if salt is changed:
val hashids = Hashids("this is my pepper")
val numbers: LongArray = hashids.decode("NkK9")
numbers
is now going to be: []
Encrypting several numbers
val hashids = Hashids("this is my salt")
val hash: String = hashids.encode(683L, 94108L, 123L, 5L)
hash
is now going to be: aBMswoO2UB3Sj
Decrypting is done the same way
val hashids = Hashids("this is my salt")
val numbers: String = hashids.decode("aBMswoO2UB3Sj")
numbers
is now going to be: [683, 94108, 123, 5]
Encrypting and specifying minimum hash length
Here we encode integer 1, and set the minimum hash length to 8 (by default it's 0 -- meaning hashes will be the shortest possible length).
val hashids = Hashids("this is my salt", 8)
val hash: String = hashids.encode(1)
hash
is now going to be: gB0NV05e
Decrypting
val hashids = Hashids("this is my salt", 8)
val numbers: String = hashids.decode("gB0NV05e")
numbers
is now going to be: [1]
Specifying custom hash alphabet
Let's set the alphabet that consist of only four letters: "0123456789abcdef"
val hashids = Hashids("this is my salt", 0, "0123456789abcdef")
val hash: String = hashids.encode(1234567)
hash
is now going to be: b332db5
Repeating numbers
val hashids = Hashids("this is my salt")
val hash: String = hashids.encode(5, 5, 5, 5);
You don't see any repeating patterns that might show there's 4 identical numbers in the hash: 1Wc8cwcE
Same with incremented numbers:
val hashids = Hashids("this is my salt")
val hash: String = hashids.encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
hash
will be: kRHnurhptKcjIDTWC3sx
Incrementing number hashes:
val hashids = Hashids("this is my salt")
val hash1: String = hashids.encode(1) /* NV */
val hash2: String = hashids.encode(2) /* 6m */
val hash3: String = hashids.encode(3) /* yD */
val hash4: String = hashids.encode(4) /* 2l */
val hash5: String = hashids.encode(5) /* rD */
Contact
Follow me @leprosus, @IvanAkimov, @fanweixiao, @spuklo
License
MIT License. See the LICENSE
file.
*Note that all licence references and agreements mentioned in the kotlin-hashids README section above
are relevant to that project's source code only.