GPT实现的企业信用代码校验函数
  T2OqV3qDOzaQ 2023年11月30日 22 0
function ValidateEnterpriseCode(EnterpriseCode: string): Boolean;
var
  i, sum, code, weight: Integer;
begin
  Result := False;
  
  // 企业信用代码长度校验
  if Length(EnterpriseCode) <> 18 then
    Exit;
    
  // 企业信用代码权重因子
  const factor: array[1..17] of Integer = (1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28);
  
  // 计算企业信用代码前17位的加权和
  sum := 0;
  for i := 1 to 17 do
  begin
    code := Ord(EnterpriseCode[i]) - Ord('0');
    weight := factor[i];
    sum := sum + code * weight;
  end;
  
  // 计算校验码
  code := 31 - sum mod 31;
  
  // 校验企业信用代码最后一位校验码
  if code = 31 then
    code := 0;
    
  if code <> Ord(EnterpriseCode[18]) - Ord('0') then
    Exit;
    
  Result := True;
end;

 

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月30日 0

暂无评论

推荐阅读
T2OqV3qDOzaQ