• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unusual behavior of Simple Cipher Program

 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If I give the input as "vasiqmz" or a word such as "x","y" then the output which I'm getting is kinda confusing....

 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Output :
Enter the text you want to cipher.
vasiqmz
The cipher text is zewmuq(And a box symbol appears which i'm not able to print it here)

I know the reason is because of the else loop but one thing i'm not getting is..if there is no char at a given position then it should display it's value as null instead of a symbol which in case here is a box.

Any reason for that ???

Thanks for reading it....
Any comments on the program....
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What gets stored in the coded string when shift >= alphabets.length?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that it's possible the text won't be encoded at all.
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:What gets stored in the coded string when shift >= alphabets.length?


If the IF loop is correct then nothing gets stored in that position...If nothing gets stored then that position should contain a "null" value instead of any symbol..I mean after all the default value of char is null....
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what would a null character print out as?
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:And what would a null character print out as?


Ok i get it now....if there is nothing in that position then it'll store "'\u0000'" or "0" which is basically a null value and a null value is printed out as a box symbol....

Thanks a lot for reading the program and helping me out with the problem....David.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem--glad to help :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic