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
- www.onlinegdb.com
- www.programiz.com
- */
- #include <stdio.h>
- int msgArrCnt;
- //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;
- //printf("%p %p\n", srtg, endg); Out: 0x7ffcbcb46de1 0x7ffcbcb46ded
- }
- }
- int main(){
- /*
- _ _ _____ _ _ ___ __ __ ___ ____ _ ____
- | | | | | ____| | | | | / _ \ \ \ / / / _ \ | _ \ | | | _ \
- | |_| | | _| | | | | | | | | \ \ /\ / / | | | | | |_) | | | | | | |
- | _ | | |___ | |___ | |___ | |_| | \ V V / | |_| | | _ < | |___ | |_| |
- |_| |_| |_____| |_____| |_____| \___/ \_/\_/ \___/ |_| \_\ |_____| |____/ by Renz.
- using this code you can generate Hello, World!
- ||
- _||_
- \ /
- \/ */
- char code[] = "1422x6c76f7266x502c6f2c5x56c64x862x4";
- 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"
- // 48656c6c6f2c20576f726c6421 >> NORMAL
- // Decoding the code:
- // First, the we should reverse the code
- strRvrs(code);
- // ANS: 4x268x46c65x5c2f6c205x6627f67c6x2241
- //printf("%s \n",code);
- // Second, 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 newCode[length];
- int x, y, newLen;
- while (x < length){
- if (code[x] == 'x' && code[x+1] >= '1' && code[x+1] <= '9'){
- int revLen = code[x+1] - '0';
- //printf("::%i", revLen);
- int y;
- 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)
- // im a bit lazy now but this code will do the job copying each char in the newCode
- sprintf(newCode, "%c", code[x]);
- else
- sprintf(newCode, "%s%c", newCode, code[y]);
- /* printf("%c.\n",code[i]); */
- // counting the new length of the newCode
- newLen++;
- }
- //printf("%c%c-\n", code[x], code[x+1]);
- 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)
- sprintf(newCode, "%c", code[x]);
- else
- sprintf(newCode, "%s%c", newCode, code[x]);
- // counting the new length of the newCode
- newLen++;
- }
- x++;
- }
- // ANS: 48656c6c6f2c20576f726c6421
- //printf("---%s---", newCode);
- //printf("%s \n",code);
- int arrSize = length/ 2;
- char tmp[64];
- int tmpInt = 0;
- int strIndx = 0;
- int strCnt = 0;
- int tmpIntArr[arrSize];
- // Let's start
- int i = -1;
- while (i <= newLen){
- tmp[strCnt-1] = newCode[i];
- if (strCnt == 2){
- tmpInt = hexConvToInt(tmp);
- tmpIntArr[strCnt] = tmpInt;
- printf("%c", tmpInt);
- //printf("%c %i %i %i\n", tmpInt , tmpInt, strCnt,i/2);
- strIndx++;
- strCnt = 0;
- }
- i++;
- strCnt++;
- }
- //printf("\n"); TEKA LANG DI KO ALAM KUNG NEED NG NEWLINE
- /*
- OUTPUT:
- 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