Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
ffe3cbad
Commit
ffe3cbad
authored
11 months ago
by
Henrik (Grubba) Grubbström
Browse files
Options
Downloads
Patches
Plain Diff
Crypto.Koremutake: Fix some warnings.
parent
6528ba0f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Crypto.pmod/Koremutake.pmod
+24
-8
24 additions, 8 deletions
lib/modules/Crypto.pmod/Koremutake.pmod
with
24 additions
and
8 deletions
lib/modules/Crypto.pmod/Koremutake.pmod
+
24
−
8
View file @
ffe3cbad
...
@@ -13,8 +13,12 @@
...
@@ -13,8 +13,12 @@
//! sequence of syllables. The general idea is that word-sounding
//! sequence of syllables. The general idea is that word-sounding
//! pieces of information are a lot easier to remember than a sequence
//! pieces of information are a lot easier to remember than a sequence
//! of digits.
//! of digits.
//!
//! @note
//! This module implements an API that is similar to (but NOT compatible
//! with) the generic @[Crypto.Cipher] API.
protected constant table = ({
protected constant
array(string(7bit))
table = ({
"BA", "BE", "BI", "BO", "BU", "BY", "DA", "DE",
"BA", "BE", "BI", "BO", "BU", "BY", "DA", "DE",
"DI", "DO", "DU", "DY", "FA", "FE", "FI", "FO",
"DI", "DO", "DU", "DY", "FA", "FE", "FI", "FO",
"FU", "FY", "GA", "GE", "GI", "GO", "GU", "GY",
"FU", "FY", "GA", "GE", "GI", "GO", "GU", "GY",
...
@@ -34,22 +38,30 @@ protected constant table = ({
...
@@ -34,22 +38,30 @@ protected constant table = ({
});
});
//! Encode an integer as a koremutake string.
//! Encode an integer as a koremutake string.
string(8bit) encrypt(int m) {
//!
string c="";
//! @note
//! Encrypts an integer. This is not compatible with the
//! @[Crypto.Cipher] API.
string(7bit) encrypt(int m) {
string(7bit) c="";
while(m) {
while(m) {
c =
[string]
table[m&127] + c;
c = table[m&127] + c;
m >>= 7;
m >>= 7;
}
}
return c;
return c;
}
}
//! Decode a koremutake string into an integer.
//! Decode a koremutake string into an integer.
int decrypt(string(8bit) c) {
//!
//! @note
//! Returns an integer. This is not compatible with the
//! @[Crypto.Cipher] API.
int decrypt(string(7bit) c) {
int m;
int m;
c = upper_case(c);
c =
[string(7bit)]
upper_case(c);
while(sizeof(c)) {
while(sizeof(c)) {
if(sizeof(c)==1) error("Error in cryptogram.\n");
if(sizeof(c)==1) error("Error in cryptogram.\n");
string w = c[..1];
string
(7bit)
w = c[..1];
c = c[2..];
c = c[2..];
if( (< 'R', 'T' >)[w[1]] ) {
if( (< 'R', 'T' >)[w[1]] ) {
...
@@ -73,6 +85,7 @@ string(7bit) name() { return "koremutake"; }
...
@@ -73,6 +85,7 @@ string(7bit) name() { return "koremutake"; }
int block_size() { return 1; }
int block_size() { return 1; }
int key_size() { return 0; }
int key_size() { return 0; }
//!
class `() {
class `() {
string(7bit) name() { return "koremutake"; }
string(7bit) name() { return "koremutake"; }
...
@@ -92,7 +105,10 @@ class `() {
...
@@ -92,7 +105,10 @@ class `() {
}
}
this_program make_key() { return this; }
this_program make_key() { return this; }
int|string(8bit) crypt(int|string(8bit) x) {
//! @note
//! Encrypts or returns an integer. This is not compatible with the
//! @[Crypto.Cipher] API.
int|string(7bit) crypt(int|string(7bit) x) {
if(mode) {
if(mode) {
if(!stringp(x)) error("Wrong type. Expected string.\n");
if(!stringp(x)) error("Wrong type. Expected string.\n");
return decrypt([string]x);
return decrypt([string]x);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment