#Atbash Cipher on bash

10 messages · Page 1 of 1 (latest)

visual mauve
#

@flat estuary I don't understand bush, but could you please copy and paste your code and the error message and enclose them in 3 backticks(`) to create a code block? The code shown in the screenshot is difficult to read.

This would make it easier for those helping you to read. I would appreciate your cooperation so that they can give you better advice. Thank you very much.

Please do it like this:
```
your code or error message
```

flat estuary
#

#!/usr/bin/env bash

Cipher="zyxwvutsrqponmlkjihgfedcba"
alphabet="abcdefghijklmnopqrstuvwxyz"
word="$1"
neword=""

for (( i=0; i<${#word}; i++ )); do
    for (( j=0; j<26; j++ )); do
        if [ "${alphabet:j:1}" == "${word:i:1}" ]; then
            neword+="${Cipher:j:1}"
        fi
    done
done

echo "$neword"

(from function assert_output' in file bats-extra.bash, line 394, in test file atbash_cipher.bats, line 12) assert_output "bvh"' failed

-- output differs --
expected : bvh
actual : vmxlwv

visual mauve
#

Thanks! Please use backticks (`), not single quotation marks (').

#

You can edit your post.

fierce compass
#

You may want to look at the tests and how the script is called

#

If it works when you use $2 for the input, maybe $1 isn't the word you're supposed to encrypt 😉

flat estuary
#

I just don’t understand because even when I use $2 it only does half of the tests, on other half it is fail, and not just because logic is wrong, there is no input in that half

fierce compass
#

You may want to look at the specifics of those failures

#

What is the failure when you use $2?
Did you look at the test? Do you understand how the script is called and what input is passed to it?

solid cargo
# flat estuary ``` #!/usr/bin/env bash Cipher="zyxwvutsrqponmlkjihgfedcba" alphabet="abcdefgh...
#!/usr/bin/env bash

Cipher="zyxwvutsrqponmlkjihgfedcba"
alphabet="abcdefghijklmnopqrstuvwxyz"
word="$1"
neword=""

for (( i=0; i<${#word}; i++ )); do
    for (( j=0; j<26; j++ )); do
        if [ "${alphabet:j:1}" == "${word:i:1}" ]; then
            neword+="${Cipher:j:1}"
        fi
    done
done

echo "$neword"

Even better with the three backticks and the language indicated by adding bash to the end of the starting one.