A new poetry club has opened in town, and you're thinking of attending. Because there have been incidents in the past, the club has a very specific door policy which you'll need to master, before attempting entry.
There are two doors at the poetry club, a front and a back door, and both are guarded. To gain entry, you'll need to work out the password of the day.
The password is always based on a poem and can be derived in a two-step process.
The details of the process depend on which door you are trying to enter.
All strings in this exercise will be ASCII-encoded and NUL-terminated.
This means all characters use ASCII encoding and every string ends when the '\0' (the NUL character, with value 0) is found.
These are the string instructions mentioned in this concept:
| instruction | what it does |
|---|---|
lods | loads a value from a memory location indicated by rsi into rax |
stos | stores a value from rax into a memory location indicated by rdi |
movs | copies a value from a memory location indicated by rsi and stores it in a memory location indicated by rdi |
cmps | compares the value in a memory location indicated by rsi with the value in a memory location indicated by rdi |
scas | compares the value inrax with the value in a memory location indicated by rdi |
All of them must have a suffix to indicate the size of the operation:
| suffix | size |
|---|---|
b | byte |
w | word (2 bytes) |
d | dword (4 bytes) |
q | qword (8 bytes) |
All string instructions also modify addresses in rsi and/or rdi (only on those registers the instruction uses).
By default, they increment the addresses by the size of the operation.
These instructions repeat one of the string instructions:
| instruction | where can be added | may stop earlier |
|---|---|---|
rep | movs, lods, stos | no |
repe,repz | cmps, scas | yes — stops when ZF is 0 |
repne, repnz | cmps, scas | yes — stops when ZF is 1 |
To determine the letters for the front door password, you need to respond with the first letter of the line of the poem, that the guard recites to you.
To end up with a nice password, the members of the poetry club like to use acrostic poems. This means that the first letter of each sentence forms a word. Here is an example by one of their favorite writers Michael Lockwood.
Stands so high
Huge hooves too
Impatiently waits for
Reins and harness
Eager to leaveSo when the guard recites Stands so high, you'll respond S, when the guard recites Huge hooves too, you'll respond H.
Implement the function front_door_response that takes the address in memory for a line of the poem as an argument and returns the first letter of that line.
This letter must be returned as a ASCII-encoded character, occupying 1 byte.
front_door_response("Stands so high");
// => 'S'Now that you have all the correct letters, all you need to do to get the password for the front door is to correctly capitalize the word.
Implement the function front_door_password that takes as argument the address in memory for a string containing only the combined letters you found in task 1.
It should modify the input string in-place, so it is correctly capitalized.
This means that the correct string should be stored in the same memory location of the input.
The function has no return value.
front_door_password('SHIRE');
// => buffer == "Shire"
front_door_password('shire');
// => buffer == "Shire"To determine letters for the back door password, you need to respond with the last letter of the line of the poem that the guard recites to you.
The members of the poetry club are really clever. The poem mentioned before is also telestich, which means that the last letter of each sentence also forms a word:
Stands so high
Huge hooves too
Impatiently waits for
Reins and harness
Eager to leaveWhen the guard recites Stands so high, you'll respond h, when the guard recites Huge hooves too, you'll respond o.
Note that sometimes the guard does stylistic pauses (in the form of punctuation or whitespace) when reciting the poem. You will need to ignore those pauses to derive the correct letter.
Implement the function back_door_response that takes as argument the address in memory for a line of the poem and returns the last letter of that line.
This letter must be returned as a ASCII-encoded character, occupying 1 byte.
back_door_response('Stands so high');
// => "h"
back_door_response('Stands ... so high ');
// => "h"To enter the poetry club via the back door, you need to be extra polite.
So to derive the password, this time you need to correctly capitalize the word and add ", please." at the end.
Implement the function back_door_password that accepts as arguments, in this order:
The function should store the polite version of the capitalized password in the buffer. A buffer is an array which can be used to store values in memory to move them between different functions.
This function has no return value.
back_door_password("horse");
// => "Horse, please."A new poetry club has opened in town, and you're thinking of attending. Because there have been incidents in the past, the club has a very specific door policy which you'll need to master, before attempting entry.
There are two doors at the poetry club, a front and a back door, and both are guarded. To gain entry, you'll need to work out the password of the day.
The password is always based on a poem and can be derived in a two-step process.
The details of the process depend on which door you are trying to enter.
All strings in this exercise will be ASCII-encoded and NUL-terminated.
This means all characters use ASCII encoding and every string ends when the '\0' (the NUL character, with value 0) is found.
These are the string instructions mentioned in this concept:
| instruction | what it does |
|---|---|
lods | loads a value from a memory location indicated by rsi into rax |
stos | stores a value from rax into a memory location indicated by rdi |
movs | copies a value from a memory location indicated by rsi and stores it in a memory location indicated by rdi |
cmps | compares the value in a memory location indicated by rsi with the value in a memory location indicated by rdi |
scas | compares the value inrax with the value in a memory location indicated by rdi |
All of them must have a suffix to indicate the size of the operation:
| suffix | size |
|---|---|
b | byte |
w | word (2 bytes) |
d | dword (4 bytes) |
q | qword (8 bytes) |
All string instructions also modify addresses in rsi and/or rdi (only on those registers the instruction uses).
By default, they increment the addresses by the size of the operation.
These instructions repeat one of the string instructions:
| instruction | where can be added | may stop earlier |
|---|---|---|
rep | movs, lods, stos | no |
repe,repz | cmps, scas | yes — stops when ZF is 0 |
repne, repnz | cmps, scas | yes — stops when ZF is 1 |
To determine the letters for the front door password, you need to respond with the first letter of the line of the poem, that the guard recites to you.
To end up with a nice password, the members of the poetry club like to use acrostic poems. This means that the first letter of each sentence forms a word. Here is an example by one of their favorite writers Michael Lockwood.
Stands so high
Huge hooves too
Impatiently waits for
Reins and harness
Eager to leaveSo when the guard recites Stands so high, you'll respond S, when the guard recites Huge hooves too, you'll respond H.
Implement the function front_door_response that takes the address in memory for a line of the poem as an argument and returns the first letter of that line.
This letter must be returned as a ASCII-encoded character, occupying 1 byte.
front_door_response("Stands so high");
// => 'S'Now that you have all the correct letters, all you need to do to get the password for the front door is to correctly capitalize the word.
Implement the function front_door_password that takes as argument the address in memory for a string containing only the combined letters you found in task 1.
It should modify the input string in-place, so it is correctly capitalized.
This means that the correct string should be stored in the same memory location of the input.
The function has no return value.
front_door_password('SHIRE');
// => buffer == "Shire"
front_door_password('shire');
// => buffer == "Shire"To determine letters for the back door password, you need to respond with the last letter of the line of the poem that the guard recites to you.
The members of the poetry club are really clever. The poem mentioned before is also telestich, which means that the last letter of each sentence also forms a word:
Stands so high
Huge hooves too
Impatiently waits for
Reins and harness
Eager to leaveWhen the guard recites Stands so high, you'll respond h, when the guard recites Huge hooves too, you'll respond o.
Note that sometimes the guard does stylistic pauses (in the form of punctuation or whitespace) when reciting the poem. You will need to ignore those pauses to derive the correct letter.
Implement the function back_door_response that takes as argument the address in memory for a line of the poem and returns the last letter of that line.
This letter must be returned as a ASCII-encoded character, occupying 1 byte.
back_door_response('Stands so high');
// => "h"
back_door_response('Stands ... so high ');
// => "h"To enter the poetry club via the back door, you need to be extra polite.
So to derive the password, this time you need to correctly capitalize the word and add ", please." at the end.
Implement the function back_door_password that accepts as arguments, in this order:
The function should store the polite version of the capitalized password in the buffer. A buffer is an array which can be used to store values in memory to move them between different functions.
This function has no return value.
back_door_password("horse");
// => "Horse, please."