如何将一些数字解码为timeDate? [英] How to decode some number into timeDate?

查看:80
本文介绍了如何将一些数字解码为timeDate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是这个一个的续集。



所以有什么主意如何将这个数字5252235562500解码为日期和时间19.11.2010 15:43吗?
我有更多这样的货币对,我在考虑一些脚本,将它们进行比较以找到某种模式。有什么建议要检查什么以及如何搜索模式吗?






编辑:我添加了四对我目前拥有的对。 / p>


  • 11.11.2010 16:23> 5252425372575

  • 2010.11.16 15:30> 5252922462564

  • 19.11.2010 15:39> 5252231562511

  • 19.11.2010 15:43> 5252235562500


解决方案

我想我找到了解决方案。不仅仅是简单地介绍解码算法,我还想向您展示其原因。



已链接问题表明,这是 EAN-13 格式。



这意味着代码具有12位数字和1个校验位:

  11.11.2010 16:23> 525242537257 5 
16.11.2010 15:30> 525292246256 4
19.11.2010 15:39> 525223156251 1
19.11.2010 15:43> 525223556250 0

支票位数可由



计算

  • 将偶数位置的数字值相加:2、4、6 ...(2 + 2 + 2 + 3 + 2 + 7 = 18)

  • 将此结果乘以3(18 * 3 = 54)

  • 将奇数编号位置的数字值相加:1、3、5。 。(5 + 5 + 4 + 5 + 7 + 5 = 31)

  • 求和两个结果(54 + 31 = 85)

  • 计算取10为模并从10中减去(5-10 = 5)



我计算了每个代码的校验位,它匹配并确认这些代码采用EAN-13格式。



根据规范,该代码的前两位或三位可以是国家/地区代码,因此我尝试将这些代码分开:

  11.11.2010 16:23> 52 5242537257 5 | 525 242537257 5 
16.11.2010 15:30> 52 5292246256 4 | 525 292246256 4
19.11.2010 15:39> 52 5223156251 1 | 525 223156251 1
19.11.2010 15:43> 52 5223556250 0 | 525 223556250 0

结果数字没有任何意义,因为时间越早数字越大:

5292246256 292246256

比后来的时间要好:

5223156251 223156251



这时我怀疑时间不是以二进制格式存储的。
我重新整理了数字并试图找到重复的图案。

我最终使用以下布局:

  11.11.2010 16:23> 52 52 42 53 72 57 5 
16.11.2010 15:30> 52 52 92 24 62 56 4
19.11.2010 15:39> 52 52 23 15 62 51 1
19.11.2010 15:43> 52 52 23 55 62 50 0

这是有趣的地方...



看看第三行和第四行,除了第四列和第六列外,其他都是相同的。

第四列有 15 55 。将其向后翻译,您将得到 51 55

两者的差为 55-51 = 4 就像分钟差 43-39 = 4

从代码值中减去分钟:

55-43 = 12

51-39 = 12



似乎第4列通过加12并向后存储数字来编码分钟。



现在尝试将其应用于第5列:

  11.11 .2010 16:23> 72> 27 
2010年11月16日15:30> 62> 26
19.11.2010 15:39> 62> 26
19.11.2010 15:43> 62> 26

26-15 = 11 27-16 = 11 ,因此第5列的差异为11。



从那时起,很容易,列的差异为15、14、13、12& 11.

进行一些快速计算即可得到编码方案:

 数字含义差异。 
2-1年15
4-3个月14
6-5天13
8-7分钟12
10-9小时11

以下是用于解码的简单代码段:

  union TimeFormat 
{
无符号短代码数组[5];
结构
{
未签名的短年;
个未签名的短个月;
未签名的短日;
分钟未签名;
短时未签名;
};
};

void DecodeBarcode(char * code,TimeFormat * time)
{
char buf [3]; // for atoi()
buf [2] = 0; //当然,对于(int i = 0,diff = 15; i< 5; ++ i,--diff),它必须为以空值终止的


{
buf [0] =代码[i * 2 +1];
buf [1] =代码[i * 2];
time-> codearray [i] = atoi(buf)-diff;
}
time-> year + = 2000;
}


This question is sequel of this one.

So any idea how to decode this number 5252235562500 into date and time 19.11.2010 15:43 ? I have more pairs like this and I'm thinking about some script for comparing them to find some patern. Any advice what to check and how to search for patterns ?


EDIT: I added four pairs that I curentlly have.

  • 11.11.2010 16:23 > 5252425372575
  • 16.11.2010 15:30 > 5252922462564
  • 19.11.2010 15:39 > 5252231562511
  • 19.11.2010 15:43 > 5252235562500

解决方案

I think I found the solution. Instead of simply presenting the decoding algorithm I'd like to show you the reasoning.

The answer to the linked question showed that was a barcode in EAN-13 format.

It means the codes have 12 digits and 1 check digit:

11.11.2010 16:23 > 525242537257 5
16.11.2010 15:30 > 525292246256 4
19.11.2010 15:39 > 525223156251 1
19.11.2010 15:43 > 525223556250 0

The check digit can be calculated by

  • adding the values of the digits in the even-numbered positions: 2, 4, 6 ... (2+2+2+3+2+7=18)
  • multiplying this result by 3 (18*3=54)
  • adding the values of the digits in the odd-numbered positions: 1, 3, 5... (5+5+4+5+7+5=31)
  • summing the two results (54+31=85)
  • calculating modulo 10 and subtracting it from 10 (5-10=5)

I calculated the check digit for every code, it matched and confirmed the codes were in EAN-13 format.

According to the specification, the first two or three digits of the code could be country codes, so I tried to separate these:

11.11.2010 16:23 > 52 5242537257 5 | 525 242537257 5
16.11.2010 15:30 > 52 5292246256 4 | 525 292246256 4
19.11.2010 15:39 > 52 5223156251 1 | 525 223156251 1
19.11.2010 15:43 > 52 5223556250 0 | 525 223556250 0

The resulting numbers didn't make any sense, because the earlier time had a greater number:
5292246256 or 292246256
than the later time:
5223156251 or 223156251

At this point I suspected the time wasn't stored in binary format. I reorganized the digits and tried to find repeating patterns.
I ended up with this layout:

11.11.2010 16:23 > 52 52 42 53 72 57 5
16.11.2010 15:30 > 52 52 92 24 62 56 4
19.11.2010 15:39 > 52 52 23 15 62 51 1
19.11.2010 15:43 > 52 52 23 55 62 50 0

This is where things got interesting...

Take a look at the 3rd and 4th row, these are the same except the 4th and 6th column.
The 4th column has 15 and 55. Translate it backwards and you get 51 and 55.
The difference of the two is 55 - 51 = 4 just like the difference of minutes 43 - 39 = 4
Subtract the minutes from code values:
55 - 43 = 12
51 - 39 = 12

It seems the 4th column encodes minutes by adding 12 and storing the digits backwards.

Now try to apply this to the 5th column:

11.11.2010 16:23 > 72 > 27
16.11.2010 15:30 > 62 > 26
19.11.2010 15:39 > 62 > 26
19.11.2010 15:43 > 62 > 26

26 - 15 = 11 and 27 - 16 = 11 so the difference for the 5th column is 11.

From then it's easy, the differences for the columns are 15, 14, 13, 12 & 11.
A few quick calculations and you get the encoding scheme:

Digits Meaning Diff.
 2-1    year    15
 4-3    month   14
 6-5    day     13
 8-7    minute  12
10-9    hour    11

Here's a simple code snippet for decoding:

union TimeFormat
{
    unsigned short codearray[5];
    struct
    {
        unsigned short year;
        unsigned short month;
        unsigned short day;
        unsigned short minute;
        unsigned short hour;
    };
};

void DecodeBarcode(char *code, TimeFormat *time)
{
    char buf[3]; // for atoi()
    buf[2] = 0;  // of course it has to be null-terminated

    for (int i = 0, diff = 15; i < 5; ++i, --diff)
    {
        buf[0] = code[i * 2 + 1];
        buf[1] = code[i * 2];
        time->codearray[i] = atoi(buf) - diff;
    }
    time->year += 2000;
}

这篇关于如何将一些数字解码为timeDate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆