이 블로그 검색

2023년 4월 30일 일요일

Octal Ascii Table

Decimal ASCII table

Hexadecimal Ascii Table

Ascii Table



0

Ctrl-@ NUL

1

Ctrl-A SOH

2

Ctrl-B STX

3

Ctrl-C ETX

4

Ctrl-D EOT

5

Ctrl-E ENQ

6

Ctrl-F ACK

7

Ctrl-G BEL

10

Ctrl-H BS

11

Ctrl-I HT

12

Ctrl-J LF

13

Ctrl-K VT

14

Ctrl-L FF

15

Ctrl-M CR

16

Ctrl-N SO

17

Ctrl-O SI

20

Ctrl-P DLE

21

Ctrl-Q DCI

22

Ctrl-R DC2

23

Ctrl-S DC3

24

Ctrl-T DC4

25

Ctrl-U NAK

26

Ctrl-V SYN

27

Ctrl-W ETB

30

Ctrl-X CAN

31

Ctrl-Y EM

32

Ctrl-Z SUB

33

Ctrl-[ ESC

34

Ctrl- FS

35

Ctrl-] GS

36

Ctrl-^ RS

37

Ctrl_ US

40

Space

41

!

42

"

43

#

44

$

45

%

46

&

47

'

50

(

51

)

52

*

53

+

54

,

55

-

56

.

57

/

60

0

61

1

62

2

63

3

64

4

65

5

66

6

67

7

70

8

71

9

72

:

73

;

74

75

=

76

77

?

100

@

101

A

102

B

103

C

104

D

105

E

106

F

107

G

110

H

111

I

112

J

113

K

114

L

115

M

116

N

117

O

120

P

121

Q

122

R

123

S

124

T

125

U

126

V

127

W

130

X

131

Y

132

Z

133

[

134

135

]

136

^

137

_

140

`

141

a

142

b

143

c

144

d

145

e

146

f

147

g

150

h

151

i

152

j

153

k

154

l

155

m

156

n

157

o

160

p

161

q

162

r

163

s

164

t

165

u

166

v

167

w

170

x

171

y

172

z

173

{

174

|

175

}

176

~

177

DEL

Decimal ASCII code table

Octal Ascii Table

Hexadecimal Ascii Table

Ascii Table






0

Ctrl-@ NUL

1

Ctrl-A SOH

2

Ctrl-B STX

3

Ctrl-C ETX

4

Ctrl-D EOT

5

Ctrl-E ENQ

6

Ctrl-F ACK

7

Ctrl-G BEL

8

Ctrl-H BS

9

Ctrl-I HT

10

Ctrl-J LF

11

Ctrl-K VT

12

Ctrl-L FF

13

Ctrl-M CR

14

Ctrl-N SO

15

Ctrl-O SI

16

Ctrl-P DLE

17

Ctrl-Q DCI

18

Ctrl-R DC2

19

Ctrl-S DC3

20

Ctrl-T DC4

21

Ctrl-U NAK

22

Ctrl-V SYN

23

Ctrl-W ETB

24

Ctrl-X CAN

25

Ctrl-Y EM

26

Ctrl-Z SUB

27

Ctrl-[ ESC

28

Ctrl- FS

29

Ctrl-] GS

30

Ctrl-^ RS

31

Ctrl_ US

32

Space

33

!

34

"

35

#

36

$

37

%

38

&

39

'

40

(

41

)

42

*

43

+

44

,

45

-

46

.

47

/

48

0

49

1

50

2

51

3

52

4

53

5

54

6

55

7

56

8

57

9

58

:

59

;

60

61

=

62

63

?

64

@

65

A

66

B

67

C

68

D

69

E

70

F

71

G

72

H

73

I

74

J

75

K

76

L

77

M

78

N

79

O

80

P

81

Q

82

R

83

S

84

T

85

U

86

V

87

W

88

X

89

Y

90

Z

91

[

92

93

]

94

^

95

_

96

`

97

a

98

b

99

c

100

d

101

e

102

f

103

g

104

h

105

i

106

j

107

k

108

l

109

m

110

n

111

o

112

p

113

q

114

r

115

s

116

t

117

u

118

v

119

w

120

x

121

y

122

z

123

{

124

|

125

}

126

~

127

DEL

2023년 4월 29일 토요일

find number Problem Solved: Uncover the Most Efficient Java Algorithm

Problem

Problem_Link

Problem Solving Approach

  • Odd digit numbers have a pattern

    1

    3

    5

    7

    9

    11

    13

    15

    17

    19

    31

    33

    35

    37

    39

    51

    53

    55

    57

    59

    71

    73

    75

    77

    79

    91

    93

    95

    97

    99

    101

    103

    105

    107

    109

  • As seen above, the pattern repeats every 5 numbers.

  • Therefore, we can know the position of each digit by dividing N by 5.

  • If we know the position of each digit, we can find out what number will be in that position (1, 3, 5, 7, 9)

  • Let's take the 13th odd digit number as an example

    • The rightmost digit (ones place) in 13 is the 3rd.

    • According to the odd digit pattern, the third number is 5.

    • The second rightmost digit (tens place) in 13 is the 2nd.

    • According to the odd digit pattern, the second number is 3.

    • In conclusion, the 13th odd digit number is 35.

  • Let's take the 27th odd digit number as an example

    • The rightmost digit (ones place) in 27 is the (27%5) 2nd.

    • According to the odd digit pattern, the second number is 3.

    • Excluding the calculated digits from 27, we get 27-27%5 = 27/5=5.

    • The second rightmost digit (tens place) is the (5%5) 5th.

    • According to the odd digit pattern, the fifth number is 9.

    • In conclusion, the 27th odd digit number is 93.

  • There is something slightly incorrect with the above pattern. For example, 5%5 is 0. However, we want the pattern to follow the table above.

    - n % 5 = 0 //5th number = 9
    - n % 5 = 1 //1th number = 1
    - n % 5 = 2 //2th number = 3
    - n % 5 = 3 //3th number = 5
    - n % 5 = 4 //4th number = 7

    To fix this, we subtract 1 from n.

    - n-1 % 5 = 0 //1th number = 1
    - n-1 % 5 = 1 //2th number = 3
    - n-1 % 5 = 2 //3th number = 5
    - n-1 % 5 = 3 //4th number = 7
    - n-1 % 5 = 4 //5th number = 9
  • Lastly, when we get 0, 1, 2, 3, 4, the actual numbers we want are 1, 3, 5, 7, 9. To optimize this, we multiply by 2 and add 1.

    0*2+1=1
    2*2+1=3
    3*2+1=5
    4*2+1=7
    5*2+1=9

Time O(log n), Space O(1)

class Solution
{
    /**
     * Finds the Nth number containing only odd digits.
     *
     * @param N The position of the desired number.
     * @return The Nth number containing only odd digits.
     */
    public long findNumber(long N)
    {
        // The variable to store the final result
        long result = 0;
        // The variable to represent the digit position (1, 10, 100, ...)
        long position = 1;

        // Continue until N is greater than 0
        while (N > 0)
        {
            // Calculate the odd digit by subtracting 1 from N and dividing by 5
            long oddDigit = ((N - 1) % 5) * 2 + 1;
            // Subtract 1 from N and divide by 5 to prepare for the next digit calculation
            N = (N - 1) / 5;
            // Add the odd digit multiplied by the current position to the result
            result += oddDigit * position;
            // Move to the next digit position
            position *= 10;
        }

        // Return the Nth number containing only odd digits
        return result;
    }
}

Explanation

  • The given integer N is repeatedly divided by 5 during the computation process, which reduces its value. In this process, odd-digit numbers are generated. The loop continues as long as N is greater than 0.

  • With each iteration, N is updated to (N - 1) / 5. This process reduces N by more than half, causing N to decrease significantly with each iteration. Since N is almost halved with each iteration, the time complexity can be considered as O(log N).

2023년 4월 25일 화요일

SQL Injection Data Extraction Process

 


Presume

Make a guess about what SQL query the server might be using.

Based on the results, make a guess about what the server is doing, such as whether it is performing authentication and identification at the same time or separately, and whether it can search for the term "over" to find "overwatch".

Vulnerability Assessment

Check whether SQL injection is possible.

Avoid using comments in queries as much as possible.

Check whether the login authentication and identification are separated or done together.

Select SQL Query

Choose an appropriate SQL injection method based on whether a list is displayed or not when searching.

For example, if a list is displayed, use In-band SQLi. If an error message is displayed, use Error-based SQLi. If only login failure messages are displayed, use Blind SQLi.

Identifying Data Output Locations

If a list is displayed, determine how many columns are being used, as the number of columns displayed may differ from the number of columns searched by the server.

Create Base SQL Injection

Create a basic template to avoid mistakes later.

Retrieve Database, Table, and Column Names

Now that the SQL query to use and the data output position have been identified, retrieve the necessary information.

Extract Data

SQL injection successful.

How to Find Substrings in a String

 

Definition of substring

A sequence of consecutive characters within a larger string.

In other words, it is a smaller string that is written without changing the order of the characters selected from the original string or skipping any characters in the middle.

Example of substrings

Substrings of "abc": "", "a", "b", "c", "ab", "bc", "abc"

In mathematics, the empty string ("") is also considered a substring.

However, in programming problems, whitespace characters are usually not considered as substrings.

How to find substrings



Example

public static int countSubstring(String str) {
    int n = str.length();
    return n*(n+1)/2;
}

2023년 4월 24일 월요일

Efficient Algorithm in Java for Solving the Maximize The Number Problem

 Problem

Problem_Link

Problem Solving Method

  • Goal: Swap the 1 at the end and the 0 at the front.
  • Condition: The number of swaps must be less than the given k.
  • Use StringBuilder: Since the string needs to be swapped, StringBuilder is the most efficient method.
  • The last 1 must only be needed when the number of swaps is less than k.
  • The loop ends when:
    1. The number of swaps is greater than k.
    2. The loop is performed for the given length.

So, two pointers are used. 

The first pointer (i) iterates to find 0, and the second pointer (lastOneIndex) finds the 1 at the end.

After both pointers have found their values, they swap them, and if the number of swaps exceeds K, the loop stops.

Time complexity: O(n), Space complexity: O(n)

class Solution {
    public static String maximumNumber(String S, int K) {
        // Convert string S to StringBuilder for easy modification
        StringBuilder sb = new StringBuilder(S);
        int n = S.length(); // Length of the string
        int lastOneIndex = n - 1; // Variable to store the index of the last 1
        int counter = 0; // Variable to store the number of swaps

        // Find the index of the last 1 in the back
        // This index must be greater than i and the number of swaps must be less than K.
        for (int i = 0; i < n && counter < K; i++) {
            while (lastOneIndex > i && sb.charAt(lastOneIndex) == '0') {
                lastOneIndex--;
            }

            // If the current position is 0 and the last 1 is behind the current position, swap
            if (sb.charAt(i) == '0' && lastOneIndex > i) {
                sb.setCharAt(i, '1'); // Change the current position's 0 to 1
                sb.setCharAt(lastOneIndex, '0'); // Change the last 1 position to 0
                counter++; // Increase the number of swaps
            }
        }

        // Return the modified string
        return sb.toString();
    }
}

2023년 4월 23일 일요일

Efficient Algorithm in Java for Solving the Wave Array Problem

 

Problem

Problem_Link

Solution

  • Given: a sorted array
  • Condition: Convert to wave array, where the elements are sorted in wave-like order (higher, lower, higher)
  • Condition2: lexicographically smallest.

Given the values and conditions, we can solve the problem by simply swapping elements in the sorted array without the need for searching.

The condition "lexicographically smallest" implies using compareTo for comparison, which is based on Unicode.

Therefore, we can solve the problem by simply iterating through half of the sorted array and swapping the current element with the previous even element.

Time Complexity: O(n), Space Complexity: O(1)

class Solution {
    public static void convertToWave(int n, int[] a) {
        // Iterate through the array starting from index 1 and incrementing by 2
        // Swap the current element with the previous even element
        for(int i = 1; i < n; i += 2){
            // Swap the current element with the previous even element
            int temp = a[i];
            a[i] = a[i - 1];
            a[i - 1] = temp;
        }
    }
}

Logic Gate Truth Tables & Definitions

Logic Gate Truth Tables Java Code !A // NOT A&B // AND ~(A&B) // NAND A|B // OR ~(A|B) // XOR A^B // XOR ~(A^B) // XNOR ~A // Inve...