FOXCHKSUM 算法

发布于 2024-10-05 13:15:30 字数 195 浏览 12 评论 0原文

谁知道这个函数如何计算校验和值?

我的目标是在.NET 上重写 FoxPro 应用程序,保留旧数据库,但数据库中的某些值是用此函数计算的。


问题已结束。

我没有注意到FOXCHKSUM已成为项目中的内部函数。

——

但是,无论如何,感谢您的提问!

Who knows how this function calculates checksum values?

My goal is to rewrite the FoxPro application on .NET, preserving the old database, but some values in the DB were calculated with this function.


Question is closed.

I didn't notice that FOXCHKSUM has been internal function in the project.

--

But, anyway, thanx for aswers!

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

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

发布评论

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

评论(5

a√萤火虫的光℡ 2024-10-12 13:15:30

FoxPro 校验和函数 SYS(2107)SYS(2007) 使用CRC16 或 CRC32 来计算校验和值。 FOXCHKSUM 函数是否可能包装这些?

The FoxPro checksum functions SYS(2107) and SYS(2007) use CRC16 or CRC32 to calculate the checksum values. Is it possible that the FOXCHKSUM function is wrapping these?

凑诗 2024-10-12 13:15:30

在 Foxpro 中,您可以使用使用 FOXCHKSUM 函数的方法创建一个类。
然后将其编译为 COM dll,然后在 .NET 代码中使用它。

In Foxpro You could make a class with a method wich utilizes the FOXCHKSUM function.
Then compile it into COM dll and then use it in your .NET code.

萌吟 2024-10-12 13:15:30

从它明显的声音来看,它试图计算一些校验和值......可能是记录级别,或特定的字段内容。我会查看原始的 VFP 代码,看看传​​递给函数调用的内容以获取结果。然后,我会研究一下也处理加密/校验和(例如 MD5)的 .Net 库。然后,您可以尝试使用相同的字符串调用标准 .net 函数,直到找到哪个函数给出相同的结果,然后您就不必处理 COM。我什至不知道 FoxChkSum 是 VFP 编码函数还是外部 .fll 或 .dll。如果是VFP代码,我也许可以帮你解密。

From the obvious sounds of it, its trying to calculate some check-sum value... maybe record level, or specific field content. I would look in the original VFP code to see what is being passed to the function call to get the results back. Then, I would look into the .Net libraries that also deal with encryption / checksums such as MD5 as a simple one. Then, you can try calling a standard .net function with the same string until you find out which one gives you the same results, then you don't have to deal with COM. I don't even know if FoxChkSum is a VFP coded function or an external .fll or .dll. If its VFP code, I can probably help out decyphering it for you.

若言繁花未落 2024-10-12 13:15:30

如果有人感兴趣 - 我发现 Foxpro 算法使用函数 SYS(2107)SYS(2007) 计算 Crc16 和 Crc32。 (参见@Stuart DunkeId 的回答)。

它并不是真正的CRC,而是一些校验和计算。无论如何,该函数返回与 FoxPro 模拟相同的结果。

这是 C# 上的:

    public static uint Crc(byte[] bytes, uint seed = (uint)0, int lcBitLen = 16)
    {
        var laPower = new byte[] { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 };
        var lnBitLen = lcBitLen == 32 ? 0x8005 : 0x1021; // 1021 hex (16bit), 8005 hex (32bit)
        var lnCrc = seed == 0 ? 0xffffffff : seed;       // Reset for Each Text Block
        foreach (var byteVal in bytes)
        {
            for (var inLoop = 7; inLoop >= 0; inLoop--)
            {
                var testBit = ((lnCrc & 0x8000) == 0x8000 && (byteVal & laPower[inLoop]) != laPower[inLoop])
                              || ((lnCrc & 0x8000) != 0x8000 && (byteVal & laPower[inLoop]) == laPower[inLoop]);
                lnCrc = (lnCrc & 0x7fff)*2;
                if (testBit)
                    lnCrc = (uint)(lnCrc ^ lnBitLen);
            }
        }
        return lnCrc;
    }

If is it interested to somebody - I found Foxpro algorithm that calc Crc16 and Crc32 with functions SYS(2107) and SYS(2007). (See answer of @Stuart DunkeId).

It is not really CRC, but some checksum calculation. Anyway that function return just the same result that foxpro analog.

Here is it on C#:

    public static uint Crc(byte[] bytes, uint seed = (uint)0, int lcBitLen = 16)
    {
        var laPower = new byte[] { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 };
        var lnBitLen = lcBitLen == 32 ? 0x8005 : 0x1021; // 1021 hex (16bit), 8005 hex (32bit)
        var lnCrc = seed == 0 ? 0xffffffff : seed;       // Reset for Each Text Block
        foreach (var byteVal in bytes)
        {
            for (var inLoop = 7; inLoop >= 0; inLoop--)
            {
                var testBit = ((lnCrc & 0x8000) == 0x8000 && (byteVal & laPower[inLoop]) != laPower[inLoop])
                              || ((lnCrc & 0x8000) != 0x8000 && (byteVal & laPower[inLoop]) == laPower[inLoop]);
                lnCrc = (lnCrc & 0x7fff)*2;
                if (testBit)
                    lnCrc = (uint)(lnCrc ^ lnBitLen);
            }
        }
        return lnCrc;
    }
挖个坑埋了你 2024-10-12 13:15:30

在 Visual FoxPro 中测试稍微更新的算法(我懒得安装 C#): CRC16 运行良好,但 CRC32 给出了不同的结果......

aa = 'bbb'
? aa
? SYS(2007,aa,0,0)
? sys2007(aa,0)

FUNCTION sys2007
LPARAMETERS lcString, lnBitFlag

LOCAL lnBitLen, lnCRC, inLoop, n
lnBitLen = IIF(BITTEST(m.lnBitFlag,0), 0x8005, 0x1021)

lnCRC = 0xffffffff

FOR n = 1 TO LEN(m.lcString)
  byteVal = ASC(SUBSTR(m.lcString, m.n, 1))
  FOR inLoop = 7 TO 0 STEP -1
    testbit = BITTEST(m.lnCRC, 15) AND !BITTEST(byteVal, inLoop) OR ;
              !BITTEST(m.lnCRC, 15) AND BITTEST(byteVal, inLoop)
    lnCRC = BITLSHIFT(BITAND(m.lnCRC, 0x7fff), 1)
    IF testbit
      lnCRC = BITXOR(m.lnCRC, m.lnBitLen)
    ENDIF
  NEXT
NEXT

RETURN m.lnCRc

Testing slightly updated algorithm in Visual FoxPro (I am lazy to install C#): The CRC16 works well but CRC32 gives different results...

aa = 'bbb'
? aa
? SYS(2007,aa,0,0)
? sys2007(aa,0)

FUNCTION sys2007
LPARAMETERS lcString, lnBitFlag

LOCAL lnBitLen, lnCRC, inLoop, n
lnBitLen = IIF(BITTEST(m.lnBitFlag,0), 0x8005, 0x1021)

lnCRC = 0xffffffff

FOR n = 1 TO LEN(m.lcString)
  byteVal = ASC(SUBSTR(m.lcString, m.n, 1))
  FOR inLoop = 7 TO 0 STEP -1
    testbit = BITTEST(m.lnCRC, 15) AND !BITTEST(byteVal, inLoop) OR ;
              !BITTEST(m.lnCRC, 15) AND BITTEST(byteVal, inLoop)
    lnCRC = BITLSHIFT(BITAND(m.lnCRC, 0x7fff), 1)
    IF testbit
      lnCRC = BITXOR(m.lnCRC, m.lnBitLen)
    ENDIF
  NEXT
NEXT

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