Why is my code printing the wrong ciphertext?

Why is my code printing the wrong ciphertext?

By : Haseeb Ashraf
Date : October 17 2020, 06:10 AM
Hope this helps If you are willing to scrap the hand-coded loops, you can use the STL algorithms such as std::transform to accomplish this:
But first, there are a few things you should do:
code :
const char *alphabet = "abcdefghijklmnopqrstuvwxyz";
char ch = 'b';
int index = ch - 'a'; // same as 'b' - 'a' == 98 - 97 == 1
std::cout << alphabet[index]; // will print 'b'
char ch = 'x';
int index = (ch - 'a' + 10) % 26; // Same as ('x' - 'a' + 10) % 26 == (120 - 97 + 10) % 26  == 33 % 26 == 7
std::cout << alphabet[index]; // will print 'h'
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <cmath>

int main()
    //Input Message
    const char *alphabet="abcdefghijklmnopqrstuvwxyz";
    std::string message = "helloworld";
    std::string result;

    // set the encrypted string using the formula above and std::transform
    std::transform(message.begin(), message.end(), std::back_inserter(result),
                  [&](char ch) { return alphabet[(ch - 'a' + 10) % 26]; });
    std::cout << "Encrypted: " << result << '\n';  

    // convert back to unencrypted using the above formula and std::transform
    std::string result2;
    std::transform(result.begin(), result.end(), std::back_inserter(result2),
                  [&](char ch) 
                  { int index = ch - 'a' - 10;  index = index < 0?26 - (abs(index) % 26):index % 26; return alphabet[index];});
    std::cout << "Unencrypted: " << result2;                  
 Encrypted: rovvygybvn
 Unencrypted: helloworld

Share : facebook icon twitter icon
Ciphertext sent and ciphertext received do not match

Ciphertext sent and ciphertext received do not match

By : Arkadi Jampolski
Date : March 29 2020, 07:55 AM
I hope this helps you . Ciphertext from modern cryptographic schemes is binary. If you assume that the binary data can be interpreted as characters with some kind of character encoding (ASCII, UTF-8, etc.), then you'll be disappointed. Not all bytes make up valid printable characters. Some control characters are even interpreted in some special way which breaks the ciphertext.
That is why you don't use String-based "streams" (...Reader and ...Writer in Java) and use actual streams (...InputStream and ...OutputStream) instead.
what is wrong with this piece of code. keeps printing null

what is wrong with this piece of code. keeps printing null

By : zhwang
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I want to read each line from a file and store each line into an array of strings ,
why it prints null before each set of letter??
code :
 String[] sArray = new String[line.length()];
 sArray[i] += line;
What is wrong with this printing function in my java code?

What is wrong with this printing function in my java code?

By : Oleg Postnikov
Date : March 29 2020, 07:55 AM
This might help you print() and println() are different methods: println() adds line break.
My code is printing only false. What can be wrong?

My code is printing only false. What can be wrong?

By : Lena
Date : March 29 2020, 07:55 AM
will help you When you recurse, you don't return the result of the recursion. Change
Pattern Printing-Where am I going wrong in this C++ code?

Pattern Printing-Where am I going wrong in this C++ code?

By : Weizong Zhou
Date : March 29 2020, 07:55 AM
Any of those help In my opinion the best way to iterate over matrix is using loop in another loop.
I think this code will be helpful for you:
Related Posts Related Posts :
  • C++ pointer to const pointer
  • Is using macros to abbreviate long winded boost template names a bad practice?
  • How to detect end-of-file when using getline?
  • Converting QXmlItem to QtDomElement or similar?
  • C++ freeing static variables
  • Compiling/Debugging LZMA
  • What is the fastest way to find out the time in the windows with an accuracy of 1ms?
  • Increment order
  • C++0x atomic implementation in c++98 question about __sync_synchronize()
  • C++ - Access array (in main) from methods outside main
  • How can i stream CCTV camera to iphone from windows
  • Function that counts the number of integers in a text file?
  • "Reading" a POD preincrement result does not yield undefined behavior. Why exactly?
  • Can nullptr be emulated in gcc?
  • Swapping one widget with another in Qt
  • Fastest C++ Signal/Slot Lib without dependency
  • Isn't this an error in the book The C++ Programming Language(4 ed)?
  • Error in C++ Vector Usage: No matching member function for call to 'push_back'
  • Can someone tell me why I am unable to find the length of array using sizeof() function here?
  • How to cout a constructor?
  • printf treats *p++ differently from what happens to p
  • How to pass a constexpr array into a function
  • OpenCV building fails due to DirectX
  • How to 'backspace' using a pushbutton
  • Binary literal in condition
  • Access captured variables outside the lambda
  • Storing 4 values from each line from a txt file, into an object - C++
  • What is the most efficient way to test for duplicates in a user inputted array?
  • How to find a string in a binary file?
  • Passing variable into lambda
  • decltype(auto) function return type does not deduce && types
  • Find the unique elements of a vector C++
  • Why doesn't str != "hello" && "goodbye" work?
  • Array rotate and delete
  • Is the concept of release-sequence useful in practice?
  • Multiple spotlights in opengl doesn't work
  • The for loop isn't entered even if the initial requirement is true
  • Function is called twice from the same thread for the same object with the same call stack
  • Filling char pointer correctly
  • How Base class members gets copied in inheritance when we copy/assign derived class objects?
  • call method from a function pointer
  • Is it common to declare const pointers in C++?
  • How to check whether new threads created inside third party DLL in visual c++ application
  • I cannot convert a '2D array whit bool' to a 'void 2D array bool'(for game of life)
  • How to send variables between classes in Qt
  • What are the similarities and differences between C++'s concepts and Rust's traits?
  • Variadic templates in C++ 11 and class constructors
  • getting segmentation fault when copying arrays using std::copy
  • std::cout is decreasing CPU Usage?
  • Trying to use find_if function to locate value in vector of pairs by first element
  • Lottery simulator is returning garbage values and not the users lotto numbers and the winning numbers
  • error: expression must have integral or unscoped enum type when incrementally filling in vectors
  • auto fail to deduce correct return type
  • Pass string or wstring in a function
  • Is there a way to get some function called on every thread that gets created?
  • How can I enforce two function parameters have the same template type?
  • Using strcpy_s() and strcat_s() with dynamically allocated strings
  • Tensorflow Lite arm64 error: cannot convert ‘const int8x8_t?
  • How to pass `this` pointer from outer class to a member structure?
  • Storing integers values from file into a vectors of vector
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk