Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming in C Base 64 Decode File Write a program that accepts one command line argument, which is the name of a base-64 encoded text

Programming in C Base 64 Decode File

Write a program that accepts one command line argument, which is the name of a base-64 encoded text file.

The program is to base-64 decode the file, which is to be treated as a text file, outputting the result into a second file (to be treated as a binary file) using as the name the string of text read from the first line of the input file.

Your program should print to the console the total number of bytes written to the output file

base-64.c

#include #include #include

char map(unsigned value) { if (value < 26) return 'A' + value; if (value < 52) return 'a' + value - 26; if (value < 62) return '0' + value - 52; if (62 == value) return '+'; if (63 == value) return '/'; return '?'; }

unsigned unmap(char c) { if ('/' == c) return 63; if ('+' == c) return 62; if (isdigit(c)) return 52 + (c - '0'); if (islower(c)) return 26 + (c - 'a'); if (isupper(c)) return 0 + (c - 'A'); return 0xFFFFFFFF; }

int main(void) { char *message = "Hello World!"; unsigned data = 062434752; // 0xCA35EA; char chars[4]; printf("DATA: %o ", data); int i; for (i = 0; i < 4; i++) { unsigned value = (data >> (18 - 6 * i)) & 077; chars[i] = map(value); } printf("MSG : "); int i4; for (i4 = 0; i4 < 4; i4++) { printf("%c", chars[i4]); } printf(" "); data = 0; int i2; for (i2 = 0; i2 < 4; i2++) { unsigned value = unmap(chars[i2]); data <<= 6; data += value; } printf("DATA: %o ", data);

return EXIT_SUCCESS; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

=+2 How can the effectiveness of global virtual teams be improved?

Answered: 1 week ago

Question

=+1 What are the major issues related to international T&D?

Answered: 1 week ago