Substitution cipher: Difference between revisions

add Risc-V solution
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(add Risc-V solution)
Line 2,086:
Decoded : flee at once. we are discovered!
</pre>
 
=={{header|Risc-V}}==
<syntaxhighlight lang="risc-v">
# gnu assembler syntax
lcipher: .ascii "zyxwvutsrqponmlkjihgfedcba"
ucipher: .ascii "ZYXWVUTSRQPONMLKJIHGFEDCBA"
substitution_cipher: # (a0: char* str) (a1: uint len)
# set up temporary registers t0, t1, t3, t4
li t0, 'a
li t1, 'z
li t3, 'A
li t4, 'Z
lui t5, %hi(lcipher)
lui t6, %hi(ucipher)
 
.dcB: # begin loop
beqz a1, .dcE # break condition
lb t2, 0(a0) # load one character from a0
blt t2, t0, .dcU # lowercase check
bgt t2, t1, .dcA
addi t2, t2, -'a
addi a5, t5, %lo(lcipher)
j .dcA
.dcU: # uppercase check
blt t2, t3, .dcI
bgt t2, t4, .dcI
addi t2, t2, -'A
addi a5, t6, %lo(ucipher)
.dcA: # convert and save ciphertext character
add a5, a5, t2
lb a5, 0(a5)
sb a5, 0(a0)
.dcI: # increment registers
addi a1, a1, -1
addi a0, a0, 1
j .dcB
.dcE: # end loop
ret
</syntaxhighlight>
 
=={{header|Ruby}}==
10

edits