Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2021-06-19T15:48:16+00:00 → 2026-11-12T16:31:29+00:00
| − | <language>SchemeJS</language> |
| − | == Testseite == |
| − | |
| − | <run id="60ce11c026665"> |
| − | (string-prefix? "Racket" "R") |
| + | <language>SchemeJS</language> |
| + | == Testseite == |
| + | |
| + | <code id="d6cfac14c1bfd"> |
| + | (define gross "ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
| + | (define klein "abcdefghijklmnopqrstuvwxyz") |
| + | (define number "1234567890") |
| + | (define sonder "+-./,;:!? ") |
| + | (define platzhalter #\*) |
| + | (define alphabet (string-append gross klein number sonder)) |
| + | |
| + | (define sqr |
| + | (lambda (x) |
| + | (* x x))) |
| + | |
| + | (define quotient |
| + | (lambda (m n) |
| + | (truncate (/ m n)))) |
| + | |
| + | (define modulo |
| + | (lambda (m n) |
| + | (let ([k (floor (/ m n))]) |
| + | (truncate (* (- (/ m n) k) n))))) |
| + | |
| + | (define ggt |
| + | (lambda (m n) |
| + | (if (= n 0) |
| + | m |
| + | (ggt n (modulo m n))))) |
| + | |
| + | (define primzahl? |
| + | (lambda (n) |
| + | (letrec |
| + | ([prim? |
| + | (lambda (n t) |
| + | (cond |
| + | [(> t (sqrt n)) #t] |
| + | [(= (modulo n t) 0) #f] |
| + | [else |
| + | (prim? n (+ t 2))]))]) |
| + | (cond |
| + | [(= n 2) #t] |
| + | [(or (< n 2) (= (modulo n 2) 0)) #f] |
| + | [else |
| + | (prim? n 3)])))) |
| + | |
| + | (define string-car |
| + | (lambda (str) |
| + | (string-ref str 0))) |
| + | |
| + | (define string-cdr |
| + | (lambda (str) |
| + | (substring str 1 (string-length str)))) |
| + | |
| + | (define char-pos |
| + | (lambda (z str) |
| + | (letrec |
| + | ([pos |
| + | (lambda (n str) |
| + | (cond |
| + | [(= (string-length str) 0) 0] |
| + | [(equal? z (string-car str)) n] |
| + | [else |
| + | (pos (+ n 1) (string-cdr str))]))]) |
| + | (pos 1 str)))) |
| + | |
| + | (define pos-char |
| + | (lambda (n str) |
| + | (string-ref str (modulo (- n 1) (string-length str))))) |
| + | |
| + | (define char-cons |
| + | (lambda (z str) |
| + | (string-append (string z) str))) |
| + | |
| + | (define char-in-string? |
| + | (lambda (z str) |
| + | (cond |
| + | [(= (string-length str) 0) #f] |
| + | [(equal? z (string-car str)) #t] |
| + | [else |
| + | (char-in-string? z (string-cdr str))]))) |
| + | |
| + | (define potmod |
| + | (lambda (x y n) |
| + | (cond |
| + | [(= y 1) x] |
| + | [(odd? y) (modulo (* x (potmod x (- y 1) n)) n)] |
| + | [else |
| + | (modulo (sqr (potmod x (quotient y 2) n)) n)]))) |
| + | |
| + | (define public-key |
| + | (lambda (p q) |
| + | (letrec |
| + | ([key |
| + | (lambda (e) |
| + | (cond |
| + | [(> e (* (- p 1) (- q 1))) 1] |
| + | [(= (ggt e (* (- p 1) (- q 1))) 1) e] |
| + | [else |
| + | (key (+ e 2))]))]) |
| + | (key 3)))) |
| + | |
| + | (define private-key |
| + | (lambda (p q e) |
| + | (letrec |
| + | ([key |
| + | (lambda (d) |
| + | (cond |
| + | [(> d (* (- p 1) (- q 1))) 1] |
| + | [(= (modulo (* e d) (* (- p 1) (- q 1))) 1) d] |
| + | [else |
| + | (key (+ d 2))]))]) |
| + | (key 3)))) |
| + | |
| + | (define codieren |
| + | (lambda (str key n) |
| + | (if (= (string-length str) 0) |
| + | '() |
| + | (cons (potmod (char-pos (string-car str) alphabet) key n) |
| + | (codieren (string-cdr str) key n))))) |
| + | |
| + | (define decodieren |
| + | (lambda (ls key n) |
| + | (if (null? ls) |
| + | "" |
| + | (char-cons (pos-char (potmod (car ls) key n) alphabet) |
| + | (decodieren (cdr ls) key n))))) |
| + | |
| + | (define p 97) |
| + | (define q 103) |
| + | (define N (* p q)) |
| + | (define e (public-key p q)) |
| + | (define d (private-key p q e)) |
| + | |
| + | (define klartext1 "Das ist ein brisanter Informatik-Text!") |
| + | (define geheimcode1 (codieren klartext1 e N)) |
| + | (define neutext1 (decodieren geheimcode1 d N)) |
| + | </code> |
| + | |
| + | <run id="a2736defabbd5"> |
| + | geheimcode1 |
| + | </run> |
| + | |
| + | <code id="0433b8c7bde0b"> |
| + | (define gross "ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
| + | (define klein "abcdefghijklmnopqrstuvwxyz") |
| + | (define number "1234567890") |
| + | (define sonder "+-/.,;:!? ") |
| + | (define platzhalter #\*) |
| + | (define alphabet (string-append gross klein number)) |
| + | |
| + | (define sqr |
| + | (lambda (x) |
| + | (* x x))) |
| + | |
| + | (define modulo |
| + | (lambda (m n) |
| + | (let ([k (floor (/ m n))]) |
| + | (truncate (* (- (/ m n) k) n))))) |
| + | |
| + | ;(define mod |
| + | ; (lambda (n m) |
| + | ; (if (< n 0) |
| + | ; (- m (modulo (abs n) m)) |
| + | ; (modulo n m)))) |
| + | |
| + | (define string-car |
| + | (lambda (str) |
| + | (string-ref str 0))) |
| + | |
| + | (define string-cdr |
| + | (lambda (str) |
| + | (substring str 1 (string-length str)))) |
| + | |
| + | (define string-cons |
| + | (lambda (z str) |
| + | (string-append (string z) str))) |
| + | |
| + | (define char-pos |
| + | (lambda (z str) |
| + | (letrec |
| + | ([pos |
| + | (lambda (n str) |
| + | (cond |
| + | [(= (string-length str) 0) 0] |
| + | [(equal? z (string-car str)) n] |
| + | [else |
| + | (pos (+ n 1) (string-cdr str))]))]) |
| + | (pos 1 str)))) |
| + | |
| + | (define pos-char |
| + | (lambda (n str) |
| + | (string-ref str (modulo (- n 1) (string-length str))))) |
| + | |
| + | (define char-cons |
| + | (lambda (z str) |
| + | (string-append (string z) str))) |
| + | |
| + | (define char-in-string? |
| + | (lambda (z str) |
| + | (cond |
| + | [(= (string-length str) 0) #f] |
| + | [(equal? z (string-car str)) #t] |
| + | [else |
| + | (char-in-string? z (string-cdr str))]))) |
| + | |
| + | (define korrigieren |
| + | (lambda (str) |
| + | (cond |
| + | [(= (string-length str) 0) ""] |
| + | [(char-in-string? (string-car str) alphabet) |
| + | (char-cons (string-car str) (korrigieren (string-cdr str)))] |
| + | [else |
| + | (korrigieren (string-cdr str))]))) |
| + | |
| + | (define vor +) |
| + | (define rueck -) |
| + | |
| + | (define wandeln |
| + | (lambda (z step) |
| + | (cond |
| + | [(char-in-string? z sonder) z] |
| + | [(char-in-string? z alphabet) |
| + | (pos-char (+ (char-pos z alphabet) step) alphabet)] |
| + | [else |
| + | platzhalter]))) |
| + | |
| + | (define codieren |
| + | (lambda (str keyword richtung) |
| + | (letrec |
| + | ([keypos |
| + | (lambda (str n) |
| + | (if (= (string-length str) 0) |
| + | "" |
| + | (let ([step (- (char-pos (pos-char n keyword) alphabet) 1)]) |
| + | (char-cons (wandeln (string-car str) (richtung step)) |
| + | (keypos (string-cdr str) (+ n 1))))))]) |
| + | (keypos str 1)))) |
| + | |
| + | (define code2 "Informatik") |
| + | (define klartext2 "Das ist ein brisanter Informatik-Text!") |
| + | (define geheimtext2 (codieren klartext2 code2 vor)) |
| + | (define neutext2 (codieren geheimtext2 code2 rueck)) |
| + | </code> |
| + | |
| + | <run id="27800f60708ca"> |
| + | geheimtext2 |
</run> |