Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17011628_박찬흠 #118

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions Steganography/SteganographyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;

namespace Steganography
Expand All @@ -11,7 +11,7 @@ public enum State
Filling_With_Zeros
};

public static Bitmap embedText(string text, Bitmap bmp)
public static Bitmap embedText(string text, Bitmap bmp)//이미지 파일에 text 숨기기
{
State state = State.Hiding;

Expand All @@ -29,33 +29,33 @@ public static Bitmap embedText(string text, Bitmap bmp)
{
for (int j = 0; j < bmp.Width; j++)
{
Color pixel = bmp.GetPixel(j, i);
Color pixel = bmp.GetPixel(j, i);//파일의 픽셀

R = pixel.R - pixel.R % 2;
G = pixel.G - pixel.G % 2;
B = pixel.B - pixel.B % 2;

//픽셀별로 R,G,B 변수들을 RGB값이 각각 짝수일땐 0, 홀수일땐 1로 저장
for (int n = 0; n < 3; n++)
{
if (pixelElementIndex % 8 == 0)
{
if (state == State.Filling_With_Zeros && zeros == 8)
{
if ((pixelElementIndex - 1) % 3 < 2)
if ((pixelElementIndex - 1) % 3 < 2)//pixelElementIndex값이 3배수가 아닐때
{
bmp.SetPixel(j, i, Color.FromArgb(R, G, B));
bmp.SetPixel(j, i, Color.FromArgb(R, G, B));//픽셀의 RGB값을 저장
}

return bmp;
}

if (charIndex >= text.Length)
if (charIndex >= text.Length)//text의 길이보다 charIndex값이 더 길때, 즉 모든 text를 숨겼을때
{
state = State.Filling_With_Zeros;
}
else
{
charValue = text[charIndex++];
charValue = text[charIndex++];//숨길 text의 각각의 값을 저장
}
}

Expand All @@ -68,7 +68,8 @@ public static Bitmap embedText(string text, Bitmap bmp)
R += charValue % 2;
charValue /= 2;
}
} break;
}
break;
case 1:
{
if (state == State.Hiding)
Expand All @@ -77,7 +78,8 @@ public static Bitmap embedText(string text, Bitmap bmp)

charValue /= 2;
}
} break;
}
break;
case 2:
{
if (state == State.Hiding)
Expand All @@ -88,7 +90,8 @@ public static Bitmap embedText(string text, Bitmap bmp)
}

bmp.SetPixel(j, i, Color.FromArgb(R, G, B));
} break;
}
break;
}

pixelElementIndex++;
Expand All @@ -104,7 +107,7 @@ public static Bitmap embedText(string text, Bitmap bmp)
return bmp;
}

public static string extractText(Bitmap bmp)
public static string extractText(Bitmap bmp)//숨긴 text를 추출
{
int colorUnitIndex = 0;
int charValue = 0;
Expand All @@ -123,36 +126,39 @@ public static string extractText(Bitmap bmp)
case 0:
{
charValue = charValue * 2 + pixel.R % 2;
} break;
}
break;
case 1:
{
charValue = charValue * 2 + pixel.G % 2;
} break;
}
break;
case 2:
{
charValue = charValue * 2 + pixel.B % 2;
} break;
}
break;
}

colorUnitIndex++;

if (colorUnitIndex % 8 == 0)
{
charValue = reverseBits(charValue);
charValue = reverseBits(charValue);//뒤에서부터 추출하므로 추출한 값을 reverse

if (charValue == 0)
if (charValue == 0)//모든 text를 추출완료했을때
{
return extractedText;
return extractedText;//text를 출력하고 종료
}
char c = (char)charValue;
char c = (char)charValue;//charValuer값을 char로 변환

extractedText += c.ToString();
extractedText += c.ToString();//변환된 값을 extractedText에 저장
}
}
}
}

return extractedText;
return extractedText;//text를 출력하고 종료
}

public static int reverseBits(int n)
Expand Down