0

I'm trying a Viginere based coding code with a function that picks a word from a list and uses that word to encrypt a secret. But everytime it picks a word from the list it makes a procedure out of it, and i need it as a string. I've been trying for hours now and I can't help myself.

Thanks to everybody who answers.

(define schlüsselauswahl 
  '("fkaloruksnkdwio"
    "qpeüäasletajdns"
    "iwodöakdjsmxbeo"
    "wlpskamsjuerutz"
    "mvbsiaöeäfzenxk"
    "djqpwöymdöäakwx"
    "vjnwsanaöwpfqtz"
    "ksmflwtzwksnswf"
    "pefäösaisuenfmx"
    "iawöaüäwirztmyb"))

(define (schlüssel)
  (list-ref schlüsselauswahl (random (length schlüsselauswahl))))

(define (verschlüsselung klartext)
  (start (string->list klartext) (string->list schlüssel) '()))

(define (start klartext schlüssel ausgabe)
  (cond
    ((null? klartext) (list->string ausgabe))
    ((null? schlüssel) (start klartext ausgabe))
    (else
     (start
      (rest klartext)
      (rest schlüssel)
      (append ausgabe 
              (list
               (integer->char
                (+ (modulo (+ (- (char->integer (first schlüssel)) 97)
                              (- (char->integer (first klartext)) 97))
                           26)
                   97))))))))
Sullivan
  • 11
  • 3
  • 1
    I tried your program (after changing `lenght` to `length`) and for me `(schlüssel)` produces a string "pefäösaisuenfmx" as expected. When asking, it helps to give an example of an expression that gives the wrong result - and then explain what you expected. It's much easier to answer a question for a reader, if it is possible to reproduce the problem. – soegaard May 17 '19 at 19:14
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. I cannot see anything in the code you provided that suggests a procedure is returned. – Sylwester May 17 '19 at 21:18
  • Thanks for the Quick Awnser, but that didnt solve my problem. Still when i run the programm it gives back an error in line 15 (string->list schlüssel). It expects a String but it says that its a procedure. string->list: contract violation expected: string? given: #. – Sullivan May 18 '19 at 07:22
  • And the schlüssel in the line (define (verschlüüselung.........) is wrong i deletet this because i want the program to take the string from the randomizer and not take one the user types in – Sullivan May 18 '19 at 07:25

1 Answers1

0

Your problem is here: (string->list schlüssel).

You are not calling the procedure schlüssel, even though you certainly want to pass its return value to string->list and not the procedure itself. You need to write (string->list (schlüssel)) instead.

Or to phrase it in the terms of your question: to "convert" the procedure returning a string into a string, you need to actually call it instead of using the procedure itself.

Rörd
  • 6,556
  • 21
  • 27