如何将一些数字解码为 timeDate?

发布于 2024-10-03 21:43:12 字数 450 浏览 5 评论 0原文

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

那么知道如何将这个数字 5252235562500 解码为日期和时间 19.11.2010 15:43 吗? 我有更多这样的对,我正在考虑一些脚本来比较它们以找到一些模式。有什么建议可以检查什么以及如何搜索模式吗?


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

  • 2010年11月11日 16:23 > 5252425372575
  • 2010年11月16日 15:30 > 5252922462564
  • 2010年11月19日 15:39 > 5252231562511
  • 2010年11月19日 15:43 > 5252235562500

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忘年祭陌 2024-10-10 21:43:12

我想我找到了解决方案。我不想简单地展示解码算法,而是想向您展示推理过程。

链接问题的答案显示这是 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

结果数字没有任何意义,因为较早的时间有更大的数字:
5292246256292246256
比晚一点的时间:
5223156251223156251

此时我怀疑时间不是以二进制格式存储的。
我重新组织了数字并试图找到重复的模式。
我最终得到了这个布局:

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

这就是事情变得有趣的地方...

看一下第三行和第四行,除了第四列和第六列之外,这些都是相同的。
第 4 列有 1555。将其向后翻译,您将得到 5155
两者之差为55 - 51 = 4,就像分钟之差43 - 39 = 4
从代码值中减去分钟:
55 - 43 = 12
51 - 39 = 12

看来第四列通过添加 12 并向后存储数字来对分钟进行编码。

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

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 = 1127 - 16 = 11,因此第 5 列的差异为 11。

从那时起就很容易了,列的差异是 15、14、13、12 和 15、14、13、12 和 16。 11.
一些快速计算,您就可以得到编码方案:

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

这是一个用于解码的简单代码片段:

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;
}

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;
}
-残月青衣踏尘吟 2024-10-10 21:43:12

当您尝试解码外国时间格式时,您需要两个已知时间。看看它们之间的差异,看看它相当于什么——秒、毫秒、天,没有太多的可能性。现在您已经有了基本时间单位,您可以使用其中一个时间来查看原始时间是什么。

我上周才不得不这样做。我有两个日期:

2009-07-15 15:29:12  1247689752
2009-07-17 08:27:55  1247837275

有很多方法可以获取两个日期之间的差异。最简单的可能是 Excel,它会显示天数的差异;在本例中为 1.70744213。两种表示形式之间的差异是147523。将天数乘以一天中的秒数(24*60*60)也得到147523,所以现在我知道日期是从某个开始经过的秒数日期。

为了获得开始日期,我从日期本身减去一个日期。这在 Excel 中也是微不足道的:将日期数字除以一天中的秒数,然后减去。就我而言,它出现在 1969-12-31 19:00。这看起来有点奇怪,但我意识到我的时区在夏天与 UTC 相差 5 个小时。这告诉我时间值采用 UTC 格式,表示自 1970-01-01 以来的秒数。

When you're trying to decode a foreign time format, you need two known times. Take the difference between them and see what it equates to - second, milliseconds, days, there aren't too many possibilities. Now that you have the basic time unit, you can work with one of the times and see what the origin time is.

I just had to do this last week. I had two dates:

2009-07-15 15:29:12  1247689752
2009-07-17 08:27:55  1247837275

There are lots of ways to get the difference between two dates. The easiest is probably Excel, which will display the difference in days; in this case 1.70744213. The difference between the two representations is 147523. Multiplying the number of days by the number of seconds in a day (24*60*60) also resulted in 147523, so now I know that the date is the number of seconds elapsed from some starting date.

To get the starting date, I subtract a date from itself. Again this is trivial in Excel: divide the date number by the number of seconds in a day, then subtract. In my case it comes up 1969-12-31 19:00. This seems a little odd, but I realize that my time zone is 5 hours off of UTC in the summer. This tells me that the time value is in UTC, and represents the number of seconds since 1970-01-01.

失退 2024-10-10 21:43:12

像这样的脚本你所想的没有任何意义,因为你可以手动在 X 时间内制动它,那么你可能会在 25*X25*X< /code> 并且该程序将基于检查您定义的模式来工作,那么当您没有数千种这种类型的算法来制动但在某些小部分有所不同时,这是没有意义的。

多给一些,我就可以告诉你更多,一对就意味着什么都不知道。

Script like this what you are thinking not make any sense, because you can by hand for example brake this in time X, then probably you will be write program for this in time 25*X and this program will be working based on checking patterns what you are define then this not make sense when you don't have thousands of algorithms this type to brake but vary in some little part.

Give some more pairs then i can tell you more, one pair is to less to know anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文