All Projects → zakame → hashids.pm

zakame / hashids.pm

Licence: MIT license
Hashids, ported for Perl

Programming Languages

perl
6916 projects
Raku
181 projects

Projects that are alternatives of or similar to hashids.pm

Hashids
A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
Stars: ✭ 4,596 (+30540%)
Mutual labels:  encoding, hashids, hash, ids, database-ids
harsh
Hashids implementation in Rust
Stars: ✭ 48 (+220%)
Mutual labels:  encoding, hashids, hash, ids, database-ids
Hashids.js
A small JavaScript library to generate YouTube-like ids from numbers.
Stars: ✭ 3,525 (+23400%)
Mutual labels:  encoding, hashids, hash, ids, database-ids
laravel-hashid
HashId Implementation on Laravel Eloquent ORM
Stars: ✭ 23 (+53.33%)
Mutual labels:  hashids, hash
id-mask
IDMask is a Java library for masking internal ids (e.g. from your DB) when they need to be published to hide their actual value and to prevent forging. It has support optional randomisation has a wide support for various Java types including long, UUID and BigInteger. This library bases its security on strong cryptographic primitives.
Stars: ✭ 39 (+160%)
Mutual labels:  hashids, database-ids
Optimus
🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.
Stars: ✭ 1,084 (+7126.67%)
Mutual labels:  hashids, ids
bytes-java
Bytes is a utility library that makes it easy to create, parse, transform, validate and convert byte arrays in Java. It supports endianness as well as immutability and mutability, so the caller may decide to favor performance.
Stars: ✭ 120 (+700%)
Mutual labels:  encoding, hash
idy
👓 An ID obfuscator for ActiveRecord
Stars: ✭ 15 (+0%)
Mutual labels:  hashids, hash
Hashids.net
A small .NET package to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user.
Stars: ✭ 470 (+3033.33%)
Mutual labels:  encoding, hashids
Codetective
a tool to determine the crypto/encoding algorithm used according to traces from its representation
Stars: ✭ 121 (+706.67%)
Mutual labels:  encoding, hash
Hashlib4pascal
Hashing for Modern Object Pascal
Stars: ✭ 132 (+780%)
Mutual labels:  encoding, hash
gilfoyle
Distributed video encoding, hosting and streaming (WIP)
Stars: ✭ 73 (+386.67%)
Mutual labels:  encoding
BencodeNET
.NET library for encoding/decoding bencode and reading/writing torrent files
Stars: ✭ 133 (+786.67%)
Mutual labels:  encoding
BlockHashLoc
Recover files using lists of blocks hashes, bypassing the File System entirely
Stars: ✭ 45 (+200%)
Mutual labels:  hash
AMVtool
Qt GUI for FFmpeg designed for video editors.
Stars: ✭ 28 (+86.67%)
Mutual labels:  encoding
space-router
Framework agnostic router for single page apps
Stars: ✭ 36 (+140%)
Mutual labels:  hash
ipld-explorer-cli
🔎 Explore the IPLD directed acyclic graph with your keyboard
Stars: ✭ 22 (+46.67%)
Mutual labels:  hash
EntityEmbedding-Working Example
This repository contains a notebook demonstrating a practical implementation of the so-called Entity Embedding for Encoding Categorical Features for Training a Neural Network.
Stars: ✭ 75 (+400%)
Mutual labels:  encoding
sha3
SHA3 for Ruby is a XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing algorithm
Stars: ✭ 35 (+133.33%)
Mutual labels:  hash
morton-nd
A header-only compile-time Morton encoding / decoding library for N dimensions.
Stars: ✭ 78 (+420%)
Mutual labels:  encoding

Actions Status Coverage Status MetaCPAN Release Build Status

NAME

Hashids - generate short hashes from numbers

SYNOPSIS

use Hashids;
my $hashids = Hashids->new('this is my salt');

# encrypt a single number
my $hash = $hashids->encode(123);          # 'YDx'
my $number = $hashids->decode('YDx');      # 123

# or a list
$hash = $hashids->encode(1, 2, 3);         # 'laHquq'
my @numbers = $hashids->decode('laHquq');  # (1, 2, 3)

# also get results in an arrayref
my $numbers = $hashids->decode('laHquq');  # [1, 2, 3]

DESCRIPTION

This is a port of the Hashids JavaScript library for Perl.

Hashids was designed for use in URL shortening, tracking stuff, validating accounts or making pages private (through abstraction.) Instead of showing items as 1, 2, or 3, you could show them as b9iLXiAa, EATedTBy, and Aaco9cy5. Hashes depend on your salt value.

IMPORTANT: This implementation follows the v1.0.0 API release of hashids.js. An older API of hashids.js (v0.1.4) can be found in Hashids version 0.08 and earlier releases; if you have code that depends on this API version, please use a tool like Carton to pin your Hashids install to the older version.

This implementation is also compatible with the v0.3.x hashids.js API.

METHODS

new

my $hashids = Hashids->new();

Make a new Hashids object. This constructor accepts a few options:

my $hashids = Hashids->new(
    salt          => 'this is my salt',
    alphabet      => 'abcdefghijklmnop',
    minHashLength => 8
);
  • salt

    Salt string, this should be unique per Hashids object. Must be either as long or shorter than the alphabet length, as a longer salt string than the alphabet introduces false collisions.

  • alphabet

    Alphabet set to use. This is optional as Hashids comes with a default set suitable for URL shortening. Should you choose to supply a custom alphabet, make sure that it is at least 16 characters long, has no spaces, and only has unique characters.

  • minHashLength

    Minimum hash length. Use this to control how long the generated hash string should be.

You can also construct with just a single argument for the salt, leaving the alphabet and minHashLength at their defaults:

my $hashids = Hashids->new('this is my salt');

encode

my $hash = $hashids->encode($x, [$y, $z, ...]);

Encode a single number (or a list of numbers) into a hash string.

encrypt

Alias for "encode", for compatibility with v0.3.x hashids.js API.

encode_hex

my $hash = $hashids->encode_hex('deadbeef');

Encode a hex string into a hash string.

decode

my $number = $hashids->decode($hash);

Decode a hash string into its number (or numbers.) Returns either a simple scalar if it is a single number, an arrayref of numbers if it decrypted a set, or undef if given bad input. Use "ref" in perlfunc on the result to ensure proper usage.

You can also retrieve the result as a proper list by assigning it to an array variable, by doing so you will always get a list of one or more numbers that are decrypted from the hash, or the empty list if none were found:

my @numbers = $hashids->decode($hash);

decrypt

Alias for this "decode", for compatibility with v0.3.x hashids.js API.

decode_hex

my $hex_string = $hashids->decode_hex($hash);

Opposite of "encode_hex". Unlike "decode", this will always return a string, including the empty string if the hash is invalid.

SEE ALSO

Hashids

LICENSE

The MIT License (MIT)

Copyright (C) Zak B. Elep.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

AUTHOR

Zak B. Elep [email protected]

Original Hashids JavaScript library written by Ivan Akimov

THANKS

Props to Jofell Gallardo for pointing this excellent project to me in the first place.

Many thanks to C. A. Church and Troy Morehouse for their fixes and updates.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].