Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Hello, World!
- -by Renz Justine L. Villegas
- October 15, 2021
- Created using: Tested using:
- Visual Studio Code (LINUX) Visual Studio Code (LINUX)
- Dev-C++ v5.11 (WINDOWS)
- www.onlinegdb.com
- www.programiz.com
- https://www.jdoodle.com/c-online-compiler/
- Execution time:
- real 0m0.004s
- user 0m0.003s
- sys 0m0.001s
- */
- #include <stdio.h>
- #include <time.h>
- //makes the character uppercase
- char upprCase(char chr){
- //if the character decimal value was 97 and above
- if (chr >= 97)
- chr = chr - 32; //subtract 32 to match the decimal value of uppercase value in ASCII
- return chr;
- }
- //get the length of string
- int strLength(char* chr){
- int i = 0;
- //count until the char[i] value is null
- while (chr[i] != '\0')
- i++;
- return i;
- }
- // (wala bang exponent function [^] sa C? Sorry nasanay sa Python at Java) exponent function
- int powerOf(int base, int exp){
- int fnl = 1;
- //repeatedly multiply the base with itself in [exp value] times
- int i;
- for (i = 0; i < exp;i++)
- fnl *= base; // Ex: base = 2; exp = 3 : 2*2*2
- return fnl; // = 8
- }
- // convert hex letters [A,B,C,D,E,F] into its decimal value [10,11,12,13,14,15,16]
- int hexLettertoInt(char letter){
- //make the character uppercase, to be ok
- int r = upprCase(letter);
- //if the letter is 'A' = 10, 'B' = 11, 'C' = 12, 'D' = 13, 'E' = 14, and 'F' = 15
- return r - 55; // Ex: 'A' in Hex = 65 :: 65 - 55 == 10
- }
- int hexConvToInt(char* str){
- // store the fnl variable
- int fnl = 0;
- // get the length of the string
- int length = strLength(str);
- // loop until the value of length
- int i;
- for (i = 0; i < length ; i++){
- int curr = 0;
- int crrIndx = length - i - 1;
- // hex numbers are only 0 - 9, and the rest are A - F
- if(str[i] >= '0' && str[i] <= '9'){
- curr = str[i] - '0'; // ALWAYS REMOVE THE EMPTY CHAR to convert it into an integer
- } else {
- curr = hexLettertoInt(str[i]);
- }
- fnl = fnl + (curr*powerOf(16,crrIndx));
- }
- return fnl;
- }
- void strRvrs(char *str)
- {
- if (*str == '\0') // avoid empty char
- return;
- char *srtg ;
- char *endg ;
- // get the value of str from the memory then make it the starting point
- for ( srtg = str,
- // end point from the memory [add the length and the loc of start then subtract 1 to remove empty char]
- endg = strLength(str) - 1 + srtg;
- // loop until the start val and end val have met
- srtg < endg;
- // [increment] Ex: 0x7ffcbcb46de1 >> 0x7ffcbcb46de2
- *srtg++,
- // [decrement] Ex: 0x7ffcbcb46dec >> 0x7ffcbcb46ded
- *endg--)
- {
- // REVERSAL PROCESS
- char tmp = *srtg;
- *srtg = *endg;
- *endg = tmp;
- // Out: 0x7ffcbcb46de1 0x7ffcbcb46ded
- }
- }
- // Let's do this!
- int main(){
- /*
- _ _ _____ _ _ ___ __ __ ___ ____ _ ____
- | | | | | ____| | | | | / _ \ \ \ / / / _ \ | _ \ | | | _ \
- | |_| | | _| | | | | | | | | \ \ /\ / / | | | | | |_) | | | | | | |
- | _ | | |___ | |___ | |___ | |_| | \ V V / | |_| | | _ < | |___ | |_| |
- |_| |_| |_____| |_____| |_____| \___/ \_/\_/ \___/ |_| \_\ |_____| |____/ by Renz.
- using this code you can generate Hello, World!
- ||
- _||_
- \ /
- \/ */
- char code[] = "BDCEKDBEFEIDIFCHEFCJIDEECGHEGFEDCCBA:805f7c6x241";
- int length = strLength(code);
- // ASCII CHAR: "H e l l o , W o r l d ! "
- // HEXADECIMAL: "48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21";
- // DECIMAL: "72 101 108 108 111 44 32 87 111 114 108 100 33"
- // BDCEKDBEFEIDIFCHEFCJIDEECGHEGFEDCCBA:805f7c6x241 >> REVERSE THE WHOLE CODE
- // 142x6c7f508:ABCCDEFGEHGCEEDIJCFEHCFIDIEFEBDKECDB >> SUPPLY THE CHAR FROM LEFT TO RIGHT
- // 1422x6c76f7266x502c6f2c5x56c64x862x4 >> REVERSE THE GIVEN INDEX
- // 4x268x46c65x5c2f6c205x6627f67c6x2241 >> REVERSE THE WHOLE CODE
- // 48656c6c6f2c20576f726c6421 >> NORMAL CODE
- // Decoding the code:
- // We should reverse the code
- // Reversal function of characters
- strRvrs(code);
- // ANS: 142x6c7f508:ABCCDEFGEHGCEEDIJCFEHCFIDIEFEBDKECDB
- char dCodedR[length]; char dCoded1[length];
- int a = 0; int startA = 0;
- // Supply all the characters that stated from the left to the right
- // Using the UPPERCASE characters in the ALPHABET as it's index.
- // find the ':' character then leave and copy the values in the dCodedR variable
- while(code[a] != ':'){
- // just making sure if the curr index is zero, to avoid random objects to be taken
- if (a == 0)
- // im a bit lazy now but this code will do the job copying each char in the variable
- sprintf(dCodedR, "%c", code[a]);
- else
- sprintf(dCodedR, "%s%c", dCodedR, code[a]);
- a++;
- }
- a++; // jump an index, then start to copy the codes in dCoded1 variable
- // continue looping until we reach the length
- while (a < length){
- // just making sure if the curr index is zero, to avoid random objects to be taken
- if (startA == 0)
- // this code will do the job copying each char in the variable
- sprintf(dCoded1, "%c", code[a]);
- else
- sprintf(dCoded1, "%s%c", dCoded1, code[a]);
- startA++; // count thr current index of the loop
- a++;
- }
- // ANS:
- // dCodedR: 142x6c7f508 dCoded1: ABCCDEFGEHGCEEDIJCFEHCFIDIEFEBDKECDB
- int length1 = strLength(dCoded1); int lengthR = strLength(dCodedR);
- int l = 0; int r = 0;
- // DECODING THE CODE: from ALPHABET to ANOTHER CODE
- // from 0 to the length of dCoder1
- while (r < lengthR){
- for(l = 0; l < length1; l++)
- if(dCoded1[l] == 65 + r) // A: 65, B: 64 ...
- dCoded1[l] = dCodedR[r]; // Replace the current char
- r++;
- }
- // Reverse function of characters
- strRvrs(dCoded1);
- // ANS: 4x268x46c65x5c2f6c205x6627f67c6x2241
- // Identify if there are 'x' char inside followed by an number,
- // remove the chars 'xn' where n is the number then reverse next n numbers.
- // Ex: ..x46c65.. == ..56c6..
- char dCoded2[length1];
- int newLen = 0; int x = 0; int y = 0;
- while (x < length1){
- if (dCoded1[x] == 'x' && dCoded1[x+1] >= '1' && dCoded1[x+1] <= '9'){
- // get the length of the characters to be reversed
- int revLen = dCoded1[x+1] - '0';
- int y;
- // we should start from the current index plus one and reverse length
- // then end it from the current index plus one, decrement.
- for (y = revLen + x + 1; y > x + 1; y--){
- // just making sure if the curr index is zero, to avoid random objects to be taken
- if (x == 0)
- // will do the job copying each char in the dCoded2
- sprintf(dCoded2, "%c", dCoded1[x]);
- else
- sprintf(dCoded2, "%s%c", dCoded2, dCoded1[y]);
- // counting the new length of the dCoded2
- newLen++;
- }
- // to fix the index of the loop
- x = revLen + x + 2;
- continue;
- } else {
- // just making sure if the curr index is zero, to avoid random objects to be taken
- // copy the new code
- if (x == 0)
- // will do the job copying each char in the dCoded2
- sprintf(dCoded2, "%c", dCoded1[x]);
- else
- sprintf(dCoded2, "%s%c", dCoded2, dCoded1[x]);
- // counting the new length of the dCoded2
- newLen++;
- }
- x++;
- }
- // ANS: 48656c6c6f2c20576f726c6421
- char tmp[64]; int arrSize = length1 /2; int tmpIntArr[arrSize];
- int tmpInt = 0; int strIndx = 0; int strCnt = 0;
- // Let's start decoding the last part.
- // The current code was in hexadecimal, every 2 characters are in hex.
- int i = -1;
- while (i <= newLen){
- tmp[strCnt-1] = dCoded2[i];
- // count tayo 0 to 1 then if the strCnt is 2, then reset itself
- if (strCnt == 2){
- // conversion of the hex to int function
- tmpInt = hexConvToInt(tmp);
- // then the integer will convert into character
- tmpIntArr[strCnt] = tmpInt;
- // and print it one by one
- printf("%c", tmpInt);
- strIndx++;
- strCnt = 0;
- }
- i++;
- strCnt++;
- }
- return(0);
- }
- /*
- OUTPUT: Hello, World!
- ooooo ooooo ooooooooooo ooooo ooooo ooooooo
- 888 888 888 88 888 888 o888 888o
- 888ooo888 888ooo8 888 888 888 888
- 888 888 888 oo 888 o 888 o 888o o888 ooo
- o888o o888o o888ooo8888 o888ooooo88 o888ooooo88 88ooo88 888
- o88
- oooo oooo ooooooo oooooooooo ooooo ooooooooo oo
- 88 88 88 o888 888o 888 888 888 888 88o 8888
- 88 888 88 888 888 888oooo88 888 888 888 8888
- 888 888 888o o888 888 88o 888 o 888 888 88
- 8 8 88ooo88 o888o 88o8 o888ooooo88 o888ooo88 oo
- */
Add Comment
Please, Sign In to add comment