c# - How to get file type from encrypted file? -
how file type using c#
encrypted file (i.e. file.enc
)?
encryption method: shift cipher z256
shift cipher encryption:
yi = (xi + k) % 256
xi = (yi - k) % 256
where:
xi, = 1 : n, input in plain bytes.
yi, = 1 : n, output cipher bytes.
k shift key secret byte between 1 , 255.
if have decrypt file first, how decrypt without using exhaustive search find shift key?
i'm not talking getting .enc
can that. i'm not able determine how file before encryption such .doc
, .xls
, .pdf
, .jpg
, or .wav
file types.
what have tried:
byte[] bytearray = file.readallbytes(openfiledialog1.filename); // mean double mean = 0; (int = 0; < bytearray.length; i++) { mean += bytearray[i]; } mean = mean / bytearray.length; txtmean.text = mean.tostring("#.000"); // median bytearray.tolist().sort(); int median = bytearray[(int)math.floor((decimal)(bytearray.length / 2))]; txtmedian.text = median.tostring(); // mode var groups = bytearray.groupby(g => g); int maxcount = groups.max(g => g.count()); int mode = groups.first(g => g.count() == maxcount).key; txtmode.text = mode.tostring(); // standard deviation double standarddeviation = bytearray.select(value => (value - mean) * (value - mean)).sum(); standarddeviation = math.sqrt(standarddeviation / bytearray.length); txtstandarddeviation.text = standarddeviation.tostring("#.000"); // entropy (i don't know how part.) int entropy = 0; txtentropy.text = entropy.tostring();
so, can see take file, read bytes of file , find mean
, median
, mode
, standard deviation
, , entropy
values.
by way, don't know how find entropy value file, there formula or maybe c# built-in method? have searched, found nothing.
i thought using mode
value able determine file type, rather determines .pdf
files .pdf
files have mode of 48.
.doc
, .xls
, .docx
, .xlsx
, .jpg
, , .wav
files give me mode of 0.
i have tried reading bytes using following page(s):
ascii character codes chart 1 - https://msdn.microsoft.com/en-us/library/60ecse8t(v=vs.80).aspx ascii character codes chart 2 - https://msdn.microsoft.com/en-us/library/9hxt0028(v=vs.80).aspx
using code:
string str = encoding.ascii.getstring(bytearray).substring(0, 256);
but returns gibberish in unable determine difference in file types.
if 'caesar shift', run down alphabet, trying each possible shift, there 25 of them.
nbcm cm uh yrugjfy nbcm cm uh yrugjfy ocdn dn vi zsvhkgz pdeo eo wj atwilha qefp fp xk buxjmib rfgq gq yl cvyknjc sghr hr zm dwzlokd example uijt jt bo fybnqmf vjku ku cp gzcorng wklv lv dq hadpsoh xlmw mw er ibeqtpi ymnx nx fs jcfruqj znoy oy gt kdgsvrk aopz pz hu lehtwsl bpqa qa iv mfiuxtm cqrb rb jw ngjvyun drsc sc kx ohkwzvo estd td ly pilxawp ftue ue mz qjmybxq guvf vf na rknzcyr hvwg wg ob sloadzs iwxh xh pc tmpbeat jxyi yi qd unqcfbu kyzj zj re vordgcv lzak ak sf wpsehdw mabl bl tg xqtfiex nbcm cm uh yrugjfy
Comments
Post a Comment