K
K
kos_dev2021-09-26 18:30:31
C++ / C#
kos_dev, 2021-09-26 18:30:31

How do I know that the end of file has been reached while reading an encrypted file?

Hello.
The Vigenère cipher is implemented, it is with reading the encrypted file that the problem arises.
The file is read and written using fstream.
The problem is that when I read the encrypted file, I only get two lines, after which it apparently returns EOF.
Tell me how to read the encrypted file to the very end.

Encrypted file content

Ciphertext
[*55
C*?35D��}<G��C?45C*@�5!D�@��D�@�5'�<,F:��?16�C?(5!�<!F#�C(?35�v?5'�=�F9*<!F�D���5C!?*6��<!F#9,<,G�D�G�91< F#:�yF9(�?35�=�F91<$F�C?46�D��G�:�<-G�91<,FsC�F"9(�@�[email protected]�91=�G�9)<'G�C?+5 �< F#:�yF�:�=�G�92<F �C'?.�:�?(�:�<-G�9*�@��:�<!F#9+<+�5D�?&5C*?2�[email protected]'@�9.<'�6�[email protected]���C&?45C*�G�:��?35C)?&5C$?*5!D�@�sC�G�9#<&F9(�?35�<!F90=��6�C!?'6��<)G�:�<"F#9/�yF�91<"F9#�?25C)@�90<F$:�<G�90<-�6�D��F#9$<'F9+=�G�}v?5C&?45"�<&F:�<*G�9&<-F�D��F91=�F:�=�G�D�?(5'C!?/�[email protected]�5'[email protected]�:�=�F:�<G�:��?55'C#?46�C*?2�:�<,F9)<$F":�<$�o9<!F#9,�?)6�[email protected]��9/<,F�C ?45D�[email protected]�5C'?.�9/<'F 9(<(�o9<-F�[email protected]�5!C?45C*@��K���G�9(=�F"9+=��6�C?45!D�F9%<'F9(<,G�9(�y�5��=�F91<$F�[email protected]�5C"?*5�<.F#90=�G�90<-�5%C)?+�91<#F"91�yF:��?16�C?.6�D��F:�=�G�9+=���K���G�C*@�5$C!?5�9'<F90<-�o�����������������������������o��������䢅������Ք���މ�����Γ���ʉ���o���ݖ��������������ҏ���ی���Γ������Ѯ��ؓ����ݓ����ԓ�ݖ���ћ����ڏ��������s�ُ�ˉ�����ϟ���щ�����ݟ���׉������Ѯ���������ԏ���،���ݓ���ԉ�����������Ю��ד���҉�����K�������������������ד���Ө}���ҏ��������U��ى�ڏ�ʕ��ޖ���������Ӏ������ʉ���������ˉ���ޅ������ݓ���Ө}v���ݓ����ݓ�ޖ���ڏ�����Ֆ������ٕ}���ى�ߏ�ԉ����ɉ���������ʉ�ۏ������ۑs������؏�މ�������ז������Չ���������s��������Ӗ����ۅ�����Ӊ�ҏ����я����y���瘏���ؘ����،�䑉�����ꌸ�����������ɤ}����Γ���ى��ݖ��،���ޓ�����瘏��͓���҉����ɗ}vy


Tried in similar ways, getline doesn't return anything after the second line:
geline try
ifstream inf(inputFilename, ios::in);
    while (inf.eof() != false)
    {
      getline(inf, count);
      fileData += count + '\n';
    }
    inf.close();


memblock reads the entire file, but it can't be decrypted
memblock
ifstream inf(inputFilename, ios::in | ios::binary | ios::ate);
    inf.seekg(0, ios::end);
    int length = inf.tellg(); // Длина текста в файле
    inf.seekg(0);

    char* memblock = new char[length];
    inf.read(memblock, length);
    inf.close();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-09-26
@kos_dev

getline encounters the character EOT (0x04, End Of Text) and ends reading.
With such files it is necessary to work in a binary mode. And do not insert line breaks in them, because you will not distinguish them from characters that have become \r (0x0D) and \n (0x0A) in encoded form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question