| Bytes | Lang | Time | Link |
|---|---|---|---|
| 008 | 05AB1E | 240613T064646Z | Kevin Cr |
| 6375 | Vyxal | 240613T060534Z | lyxal |
| nan | 240613T054344Z | Williams |
05AB1E, 8 bytes
Çā<ÅfR+ç
Output as a list of characters.
Try it online or verify all test cases.
Explanation:
Ç # Convert the (implicit) input-string to a list of codepoint-integers
ā # Push a list in the range [1,length] (without popping the list)
< # Decrease each by 1 to make the range [0,length)
Åf # Map each value to its 0-based n'th Fibonacci number
R # Reverse this list
+ # Add the values in the lists at the same positions together
ç # Convert it from integers to ASCII characters with these codepoint
# (after which this list of characters is output implicitly as result)
Vyxal, 51 bitsv2, 6.375 bytes
C:ẏṘ∆F+C
Bitstring:
010101101100110100101110001100110100000001001011110
Outputs a list of characters.
Explained
C:ẏṘ∆F+C
C # Convert the input to character codes
:ẏ # And push the range [0, len(input)), without popping the character codes
Ṙ∆F # Generate the fibonacci numbers in reversed order as required
+ # Add each number to the corresponding char code
C # And convert back to characters.
💎
Created with the help of Luminespire.
def reverse_fibonacci_cipher(input_str: str) -> str:
# Calculate the length of the input string
n = len(input_str)
# Generate the first n Fibonacci numbers
fib = [0, 1]
for i in range(2, n):
fib.append(fib[-1] + fib[-2])
# Reverse the Fibonacci sequence
fib = fib[::-1]
# Encode the input string using the reversed Fibonacci sequence
encoded_chars = [chr(ord(input_str[i]) + fib[i]) for i in range(n)]
# Join the encoded characters to form the encoded string
encoded_str = ''.join(encoded_chars)
return encoded_str
# Test cases
print(reverse_fibonacci_cipher("Code")) # Output: "Epee"
print(reverse_fibonacci_cipher("Hello")) # Output: "Jfnnp"