Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -0,0 +1,3 @@
chars "AaNn" + 13
Rot13 {𝕨 ((𝕩=52)/) chars 52|26+𝕩}(chars)

View file

@ -0,0 +1 @@
Rot13 "Abcdefghijklm:Nopqrstuvwxyz_123 aBCDEFGHIJKLM-nOPQRSTUVWXYZ."

View file

@ -14,8 +14,7 @@ class Program {
};
}
static string Rot13(string s)
=> new string(message.Select(c => shift(c)).ToArray());
static string Rot13(string s) => new string(s.Select(c => shift(c)).ToArray());
static void Main(string[] args) {

View file

@ -1,21 +1,15 @@
func$ rot13 str$ .
for c$ in strchars str$
code = strcode c$
if code >= 65 and code <= 90
encCode = code + 13
if encCode > 90
encCode = 64 + encCode - 90
.
elif code >= 97 and code <= 122
encCode = code + 13
if encCode > 122
encCode = 96 + encCode - 122
.
else
encCode = code
c = strcode c$
if c >= 65 and c <= 90
c = (c + 13 - 65) mod 26 + 65
elif c >= 97 and c <= 122
c = (c + 13 - 97) mod 26 + 97
.
encStr$ &= strchar encCode
enc$ &= strchar c
.
return encStr$
return enc$
.
print rot13 "Rosetta Code"
enc$ = rot13 "Rosetta Code"
print enc$
print rot13 enc$

View file

@ -1,7 +1,7 @@
# Returns a copy of 's' with rot13 encoding.
func rot13(s) {
s.tr('A-Za-z', 'N-ZA-Mn-za-m');
s.tr('A-Za-z', 'N-ZA-Mn-za-m')
}
# Perform rot13 on standard input.
STDIN.each { |line| print rot13(line) }
STDIN.each { |line| say rot13(line) }

View file

@ -0,0 +1,15 @@
( in-place rot13, null terminated string )
@rot13 ( addr* -: addr* )
DUP2
&loop
LDAk ?{ POP2 JMP2r } STH2k
LDAk #df AND DUP #41 LTH SWP #5a GTH ORA
STH LDAk STHr
?{
DUP #df AND
#0d ADD
DUP #5a GTH #1a MUL SUB
SWP #20 AND ORA
}
STH2r STA INC2
!&loop

View file

@ -0,0 +1,32 @@
PROGRAM "Rot-13"
VERSION "0.0000"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
dec$ = ""
TYPE$ = "cleartext "
ctext$ = ""
iOffset = 13 'offset assumed to be 13 - uncomment line 11 to change
PRINT "For decrypt enter " + "<d> " + " -- else press enter > ";
dec$ = INLINE$("")
PRINT
IF LCASE$(dec$) = "d" THEN
iOffset = 26 - iOffset
TYPE$ = "ciphertext "
END IF
PRINT "Enter " + TYPE$; '' + "> ";
cad$ = UCASE$(INLINE$("> "))
FOR i = 1 TO LEN(cad$)
iTemp = ASC(MID$(cad$,i,1))
IF iTemp > 64 AND iTemp < 91 THEN
iTemp = ((iTemp - 65) + iOffset) MOD 26
PRINT CHR$(iTemp + 65);
END IF
NEXT i
END FUNCTION
END PROGRAM

View file

@ -1,38 +1,62 @@
// Warning: modifies the buffer in-place (returns pointer to in)
fn rot13(in: [] u8) []u8 {
for (in) |*c| {
var d : u8 = c.*;
var x : u8 = d;
x = if (@subWithOverflow(u8, d | 32, 97, &x) ) x else x;
if (x < 26) {
x = (x + 13) % 26 + 65 + (d & 32);
c.* = x;
const std = @import("std");
pub const Rot13 = struct {
pub fn char(ch: u8) u8 {
return switch (ch) {
'a'...'m', 'A'...'M' => |c| c + 13,
'n'...'z', 'N'...'Z' => |c| c - 13,
else => |c| c,
};
}
/// Caller owns returned memory.
pub fn slice(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]u8 {
const output = try allocator.alloc(u8, input.len);
errdefer allocator.free(output);
for (input, output) |input_ch, *output_ch| {
output_ch.* = char(input_ch);
}
return output;
}
return in;
}
const msg: [:0] const u8 =
\\Lbh xabj vg vf tbvat gb or n onq qnl
\\ jura gur yrggref va lbhe nycunorg fbhc
\\ fcryy Q-V-F-N-F-G-R-E.
;
// need to copy the const string to a buffer
// before we can modify it in-place
//https://zig.news/kristoff/what-s-a-string-literal-in-zig-31e9
var buf: [500]u8 = undefined;
fn assignStr(out: []u8, str: [:0]const u8) void {
for (str) |c, i| {
out[i] = c;
}
out[str.len] = 0;
}
const print = @import("std").debug.print;
pub fn main() void {
assignStr(&buf, msg);
print("rot13={s}\n",.{rot13(&buf)});
};
pub fn main() error{OutOfMemory}!void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const message_input =
\\@@@111@@@ Lbh xabj vg vf tbvat gb or n onq qnl
\\ jura gur yrggref va lbhe nycunorg fbhc
\\ fcryy Q-V-F-N-F-G-R-E.
;
const message_decoded = try Rot13.slice(allocator, message_input);
defer allocator.free(message_decoded);
std.debug.print(
\\{s}
\\=== Decoded to ===
\\{s}
\\
, .{
message_input,
message_decoded,
});
std.debug.print("\n", .{});
const message_encoded = try Rot13.slice(allocator, message_decoded);
defer allocator.free(message_encoded);
std.debug.print(
\\{s}
\\=== Encoded to ===
\\{s}
\\
, .{
message_decoded,
message_encoded,
});
}