-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
use Crypt::Argon2 qw/argon2d_raw argon2i_raw argon2id_raw argon2_pass argon2_verify/; | ||
|
||
# Password to hash | ||
my $password = 'my_secure_password'; | ||
my $salt = 'random_salt'; | ||
my $iterations = 3; | ||
my $memory_cost = 32 * 1024; # in KB | ||
my $parallelism = 1; | ||
my $hash_length = 32; | ||
|
||
# Hash with Argon2d | ||
my $argon2d_hash = argon2d_raw($password, $salt, $iterations, $memory_cost, $parallelism, $hash_length); | ||
print("Argon2d hash: " . unpack("H*", $argon2d_hash) . "\n"); | ||
# Hash with Argon2i | ||
my $argon2i_hash = argon2i_raw($password, $salt, $iterations, $memory_cost, $parallelism, $hash_length); | ||
print("Argon2i hash: " . unpack("H*", $argon2i_hash) . "\n"); | ||
# Hash with Argon2id | ||
my $argon2id_hash = argon2id_raw($password, $salt, $iterations, $memory_cost, $parallelism, $hash_length); | ||
print("Argon2id hash: " . unpack("H*", $argon2id_hash) . "\n"); | ||
|
||
# Encode password with Argon2d | ||
my $argon2d_encoded = argon2_pass('argon2d', $password, $salt, $iterations, $memory_cost, $parallelism, $hash_length); | ||
print "Argon2d encoded: $argon2d_encoded\n"; | ||
# Encode password with Argon2i | ||
my $argon2i_encoded = argon2_pass('argon2i', $password, $salt, $iterations, $memory_cost, $parallelism, $hash_length); | ||
print "Argon2i encoded: $argon2i_encoded\n"; | ||
# Encode password with Argon2id | ||
my $argon2id_encoded = argon2_pass('argon2id', $password, $salt, $iterations, $memory_cost, $parallelism, $hash_length); | ||
print "Argon2id encoded: $argon2id_encoded\n"; | ||
|
||
# Verify password with Argon2d | ||
# print argon2d_verify($argon2d_encoded1, $password) ? "Argon2d password is correct.\n" : "Argon2d password is incorrect.\n"; | ||
argon2_verify($argon2d_encoded, $password) ? print "Argon2d password is correct.\n" : print "Argon2d password is incorrect.\n"; | ||
# Verify password with Argon2i | ||
argon2_verify($argon2i_encoded, $password) ? print "Argon2i password is correct.\n" : print "Argon2i password is incorrect.\n"; | ||
# Verify password with Argon2id | ||
argon2_verify($salt, $password) ? print "Argon2id password is correct.\n" : print "Argon2id password is incorrect.\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use JSON::Path; | ||
|
||
# Sample Perl data structure | ||
my $data = { | ||
store => { | ||
book => [ | ||
{ category => "reference", author => "Nigel Rees", title => "Sayings of the Century", price => 8.95 }, | ||
{ category => "fiction", author => "Evelyn Waugh", title => "Sword of Honour", price => 12.99 }, | ||
{ category => "fiction", author => "Herman Melville", title => "Moby Dick", isbn => "0-553-21311-3", price => 8.99 }, | ||
{ category => "fiction", author => "J. R. R. Tolkien", title => "The Lord of the Rings", isbn => "0-395-19395-8", price => 22.99 } | ||
], | ||
bicycle => { | ||
color => "red", | ||
price => 19.95 | ||
} | ||
} | ||
}; | ||
|
||
# Create a JSON::Path object | ||
my $jpath = JSON::Path->new('$.store.book[*].author'); | ||
|
||
# Find all authors | ||
my @authors = $jpath->values($data); | ||
|
||
# Print authors | ||
print "Authors:\n"; | ||
foreach my $author (@authors) { | ||
print "$author\n"; | ||
} |