Ask coding questions

← Back to all posts
An Encryption Question. Made me lost 100000 brain cells :D
NgMarco (0)

Hi guys! I am a c++ learner and recently studying array. Yet I found one of the questions of my assignment is out of the syllabus(we only learn basic array up to this moment) and I really need some help from you guys! :)
Can you please give me some insight first? :D
Thank you!

Commentshotnewtop
NgMarco (0)

@mwilki7 no sir, it depends on the number of digit of the KEY input by the user. As an example, 1234567890 is the KEY input by user, the number n equal to 10.

mwilki7 (993)

@NgMarco
will there ever be a digit larger than the length of the whole number?
for instance: "1239" length 4, but there is a 9

NgMarco (0)

@mwilki7
(This reply is false. Sorry for causing misunderstanding.🤦😂)
Yes, every single digit of the KEY can be larger than the length of the whole number.😁
For example, length of "19" is 2, but largest digit in the number is 9.

mwilki7 (993)

@NgMarco
for example:

key = 19
sentence = "the"

encryption_table = 
     "th"
     "e "

Starting encryption with "19"
[zero-th digit] 1 - would move Column 0 to 1
[first       digit] 9 - would move Column 1 to 9 <- this would cause a seg fault
this only has 2 columns, but the 2nd digit wants to move a column 9 or am I misunderstanding something

NgMarco (0)

@mwilki7 Sorry I made a mistake in the last reply. The key wont be number 19.

mwilki7 (993)

@NgMarco ok i understand better now
are you able to use strings instead of char arrays?

for example:

char sentence[10] = "the";
string sentence = "the";
NgMarco (0)

@mwilki7 yes we can use any methods :D
BTW I made another mistake :( that the leading digit of the key can start with 0. Therefore in the last picture, there should be 3 options of key which are {01,10,11}

mwilki7 (993)

@NgMarco
a 2D array would be the easiest way to do this problem

is there a specific part of this program you don't know how to do?

NgMarco (0)

@mwilki7
i wonder how to change the columns for the encryption. :)
can i invite you to another repl to ask you about the encryption step involving the 2d arrays

SixBeeps (2289)

You could probably do this without a 2D array. Do you need to use one?

NgMarco (0)

@SixBeeps
No sir, the tutor said we can do whatever we can to solve this question.
Can I ask what method I can use instead?